Race condition on Android with React Native #83
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MichaelContento/redux-storage#83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Using the example code you provided, I get the following console log on iOS, where the app works just fine.
But on Android, the storage loads immediately before the react native app starts up, causing some issues with waiting for the state to be loaded from disk. Here's the Android log.
Workaround
Rather than relying on
componentWillReceivePropsto check if store has loaded, I'll make that check in both mycomponentDidMountandcomponentWillReceivePropsmethods.I'd recommend using a reducer to keep track of the loaded-state and not in a component directly! With a custom reducer this flag is always present in the state and can be consumed by whatever component you want. Also there is no race condition, as the loader (created by
storage.createLoader) requires your reducer function as argument.Have a look at this example, as it describes how to listen on the
LOAD/SAVEaction.If this does solve your question / issue, please close this thread. Otherwise keep on asking 😄
@michaelcontento your suggestion is actually exactly what I ended up doing. Thanks!