I am trying to get userdata from firestore based on uid obtained from authStatechanged in mobx. But when i try to access it in useEffect, it shows value is undefined but if i print its value in body it shows after slight delay. What should i fo to get that value in useeffect.
index.js
useEffect(() => {
setposts(props.posts);
authUser && setuser(authUser) ; //it shows authuser is null
}, []);
return (
<Layout>
{authUser && authUser.uid} //it gives correct value after delay
</Layout>
store.js
class Store {
@observable authUser = null
constructor(){
const result = firebase.auth().onAuthStateChanged(authUser => {
if(authUser){
this.authUser = authUser
}
})
}
}