Javascript/mongodb: Usestate Problem Null Values On Initial Registration
I'm getting a problem with useState(). The problem is whenever the page refresh userId has no value because I set it but inside my code I acquire it's value. const [userId, setUser
Solution 1:
There are two things,
Refreshing page actually SHOULD remove all the data react is holding. If u want to persist data in-between refreshes then use sessionStorage
Setting a value via useState hook shows the value AFTER a render. So, you cannot do
setUserId
and in the next promiseagentId: userId
and expect to get the updated value. You will get the last value.
So instead of agentId: userId
do agentId: userData
that should be a quick fix.
Post a Comment for "Javascript/mongodb: Usestate Problem Null Values On Initial Registration"