You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have a pretty limited store in my app with 12 keys, some with additional objects so roughly 150 keys in total.
I'm using useReducer to keep track of it and it works fine. But I want to make sure the data is persistent between sessions or device restarts so I added AsyncStorage to save the state whenever it updates.
The way I do it now is to have a useEffect in my Store Provider that loads the AsyncStorage, if it exists, when the App starts, and whenever an action is dispatched in the reducer, if the state was changed, I JSON.stringify my entire store and save it to AsyncStorage.
But is there a better way to do this? The hook sounded like a good plan, but it doesn't really seem to be a hook since it doesn't handle state.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I have a pretty limited store in my app with 12 keys, some with additional objects so roughly 150 keys in total.
I'm using useReducer to keep track of it and it works fine. But I want to make sure the data is persistent between sessions or device restarts so I added AsyncStorage to save the state whenever it updates.
The way I do it now is to have a useEffect in my Store Provider that loads the AsyncStorage, if it exists, when the App starts, and whenever an action is dispatched in the reducer, if the state was changed, I JSON.stringify my entire store and save it to AsyncStorage.
But is there a better way to do this? The hook sounded like a good plan, but it doesn't really seem to be a hook since it doesn't handle state.
Beta Was this translation helpful? Give feedback.
All reactions