-
-
Save rishichawda/aee7bf47cc66d07b6c6b7fdc0a02b457 to your computer and use it in GitHub Desktop.
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 { 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