Skip to content

Instantly share code, notes, and snippets.

@rishichawda
Created September 20, 2018 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rishichawda/aee7bf47cc66d07b6c6b7fdc0a02b457 to your computer and use it in GitHub Desktop.
Save rishichawda/aee7bf47cc66d07b6c6b7fdc0a02b457 to your computer and use it in GitHub Desktop.
import { combineReducers, createStore, applyMiddleware } from 'redux';
import storage from 'redux-persist/lib/storage';
import { persistReducer, persistStore } from 'redux-persist';
import promise from 'redux-promise';
// Create the root reducer as you normally would.
const rootReducer = combineReducers({
myPersistentData: dataReducer,
someMorePresistentData: randomReducer,
});
/*
Create the configuration object to be used for transforming our simple
root reducer into a property on persistent storage.
*/
const config = {
key: '_myPersistentDataKey',
storage,
};
// Make your reducer persistent with persistReducer()
const reducer = persistReducer(config, rootReducer);
const store = createStore(
reducer, // Your persistent reducer
{}, // Initial store state
applyMiddleware(promise), // middleware(s)
);
// Convert your store to be persistent accross app sessions.
const persist = persistStore(store);
export default { store, persist };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment