Skip to content
Advertisement

state is not getting updated for a new user in react native

My app has a test sheet, if a user passes the test he is shown a passing screen and then the state is saved using asyncstorage. But the problem here is, let’s say i have user A and user B and user A is currently logged in, he passed the test and the app shows him passing screen and the state is saved. Now user A logs out and user B logs in, he is a completely new user he has never given test before but my app has still saved the state for the user A and keeps showing passing screen even to the user B rather it should not.Can someone help me with this issue?

code:

JavaScript

my user logs out using auth().signOut() by the way! It would be great if this issue gets solved i am dealing with it for the past 4,5 days now!

Advertisement

Answer

I think this is the problem:

JavaScript

key is defined at the top level, outside of the react lifecycle, and thus is subject to having stale values. auth().currentUser may change, the value of key will not (I think). Instead of storing key as a string, try storing it as a function:

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