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
setUserIdand in the next promiseagentId: userIdand 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"