redux-restore
This is a simple wrapper around async storage that saves your store data to AsyncStorage
in react native. Works with Android and iOS! Tested on 0.18
Install
npm install redux-restore --save
Setup
Register Middleware
Create your store with the storage
middleware
let createStoreWithMiddleware = createStore let reducers = reducers
Pass an array with reducer names. Each one you pass will be saved to storage.
Use RestoreProvider
Use this instead of the usual Provider
from redux. When you load the app, it will dispatch from storage with the current state, if there is any.
Component { return <RestoreProvider store=store> <Scene /> </RestoreProvider> ; }
Add an action to your reducer
case 'authentication': delete actiontype return Immutable
Create a new case with the name of your reducer. This will be called with all of the stored state.
That's it! You're all set!
Conclusion
This library is one of the nicest AsyncStorage wrappers I've seen. The only problem I see is the way the state is restored. I think the RestoreProvider
component could be done better.