简体   繁体   中英

react state sets to null after redirecting from another page using history() and later updates to the correct value - Firebase

I get this error when the profile page(redirects from login) finishes loading 'Unhandled Rejection (TypeError): Cannot read property 'email' of null'. Can someone explain how I could wait for the state to set before executing another code

Use the onAuthState listener like here:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  }
});

You can find more about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM