Skip to content

Instantly share code, notes, and snippets.

@Maluen
Created September 5, 2018 11:11
Show Gist options
  • Save Maluen/c38bfa0d28eea650176692092816af91 to your computer and use it in GitHub Desktop.
Save Maluen/c38bfa0d28eea650176692092816af91 to your computer and use it in GitHub Desktop.
React native store.js using redux-persist
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