Created
September 5, 2018 11:11
-
-
Save Maluen/c38bfa0d28eea650176692092816af91 to your computer and use it in GitHub Desktop.
React native store.js using redux-persist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import { persistStore, persistReducer } from 'redux-persist'; | |
import storage from 'redux-persist/lib/storage'; // defaults to AsyncStorage for react-native | |
import rootReducer from './reducers/root'; | |
const persistedReducer = persistReducer({ | |
key: 'root', | |
storage, | |
}, rootReducer); | |
const store = createStore(persistedReducer, applyMiddleware( | |
thunk, | |
)); | |
const persistor = persistStore(store); | |
//persistor.purge(); // USE ON DEVELOPMENT TO CLEAR PERSISTED STATE | |
export { store, persistor }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment