In React, how to get current user details after updating the Moralis User object

I need get the current user details after updating the Moralis User object.

Here is my code

await setUserData({ "ethAddress": userEthAddress });
await refetchUserData();
console.log("user", user);
console.log("currentUser", Moralis.User.current());

After the account change event I have update the userData with new user’s ethAddress. But I couldn’t get the updated info. Both user and currentUser is displaying the old user’s userId.

did you try with useEffect?

1 Like

Yes, I tried it,

 useEffect(() => {
    console.log("user", user);
  }, [user]);

UseEffect haven’t triggered.

1 Like

maybe its because your useEffect has the depednancy on user. what if you try putting it as an empty array so that the useeffect will definitely run on page refresh, although this wont handle the case where you update the user but you could try this first. if its not triggering though as u currently have it, its definitely because of the user dependancy.

1 Like

useEffect is triggering on page refresh even if we add a dependency for it, the problem is I can’t get the updated user info.

Is there any way to solve this issue? Or else can anyone tell me why the user does not update?

What version of the sdk are you using?



You could try with latest version in case that some bugs were fixed meanwhile.

Update your sdk with npm install moralis


@cryptokid @taha I have tried with latest version. But the issue is still not solved.