Skip to content
Advertisement

Unable to set state after getting document data from Firestore

I am trying to do a User Profile page and after getting the data from Firestore, I’m unable to set the data into the userProfile state.

JavaScript

I got this error:

enter image description here

The console log shows that the userProfile state is undefined, however, I can retrieve the data from Firestore without any issues as shown in the console log.

enter image description here

Advertisement

Answer

JavaScript

Instead of of const {userProfile, setUserProfile} = useState(null);

replace it with const [userProfile, setUserProfile] = useState(null);

Because u are using curly brackets in {userProfile,setUserProfile}

u need to replace it with square brackets [userProfile,setUserProfile]

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement