DEV Community

Discussion on: Filter on map function in React JS

Collapse
 
tylerjnewman profile image
Tyler Newman • Edited

I would do it this way:

const [userId, setUserId] = useState("");
const updatedUser = list.find((user) => user._id === userId);
const { email, username, password } = updateUser;
Enter fullscreen mode Exit fullscreen mode

const updateUserId = (id) => setUpdateId(id) is redundant as well as you can just use setUserId directly

Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Yes but I needed 3 different states of email , username and password because i have three inputs which change these states and update the value using those input fields

Collapse
 
jamesthomson profile image
James Thomson

Personally I would group these as an object. They're all related, so why have seperate individual states, updaters, etc. for each?

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

If i have to send this data (I'd,email,username and password) to the backend for MongoDb query then please write the short logic for it

Collapse
 
_genjudev profile image
Larson

It was a nice "reminder" to use proper functions.

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

Okay i would try to re-code this thing
As i don't want to mess up the backend part which is already set and i am new to this 😂😂