Created
May 29, 2019 12:44
-
-
Save daverivera/b8a88377eb20ace35f78887f7445ad40 to your computer and use it in GitHub Desktop.
redux-crosstab_persist_index
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 React from 'react' | |
import { render } from 'react-dom' | |
import { createStore } from 'redux' | |
import { Provider } from 'react-redux' | |
import App from './components/App' | |
import reducer from './reducers' | |
import 'todomvc-app-css/index.css' | |
+import { persistStore, persistReducer } from 'redux-persist' | |
+import { PersistGate } from 'redux-persist/integration/react' | |
+import storage from 'redux-persist/lib/storage' | |
+import hardSet from 'redux-persist/lib/stateReconciler/hardSet' | |
+import crossBrowserListener from './utils/cross-browser-middleware' | |
+const persistConfig = { | |
+ key: 'root', | |
+ storage, | |
+ stateReconciler: hardSet | |
+} | |
+const persistedReducer = persistReducer(persistConfig, reducer) | |
-const store = createStore(reducer) | |
+const store = createStore(persistedReducer) | |
+const persistor = persistStore(store) | |
+window.addEventListener('storage', crossBrowserListener(store, persistConfig)); | |
render( | |
<Provider store={store}> | |
- <App /> | |
+ <PersistGate loading={null} persistor={persistor}> | |
+ <App /> | |
+ </PersistGate> | |
</Provider>, | |
document.getElementById('root') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment