- react-redux
- react-thunk
- react-persist
- redux
Last active
February 5, 2022 05:29
-
-
Save dialguiba/6b1fd5d05e0ac0f08950f78ac9dfed3e to your computer and use it in GitHub Desktop.
react-store-persistent
This file contains hidden or 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 ReactDOM from "react-dom"; | |
import { TodoApp } from "./TodoApp"; | |
import { store, persistor } from "./store/store"; | |
import { Provider } from "react-redux"; | |
/* */ | |
import { PersistGate } from "redux-persist/integration/react"; | |
import { HashRouter } from "react-router-dom"; | |
ReactDOM.render( | |
<React.StrictMode> | |
<Provider store={store}> | |
<PersistGate loading={null} persistor={persistor}> | |
<HashRouter> | |
<TodoApp /> | |
</HashRouter> | |
</PersistGate> | |
</Provider> | |
</React.StrictMode>, | |
document.getElementById("root") | |
); |
This file contains hidden or 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 } from "redux"; | |
import { todoReducer } from "./todoReducer"; | |
export const rootReducer = combineReducers({ | |
content: todoReducer, | |
// TODO: CAlendarReducer | |
}); |
This file contains hidden or 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 { applyMiddleware, compose, createStore } from "redux"; | |
import thunk from "redux-thunk"; | |
import { rootReducer } from "../reducers/rootReducer"; | |
/* */ | |
import { persistStore, persistReducer } from "redux-persist"; | |
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web | |
const persistConfig = { | |
key: "root", | |
storage, | |
}; | |
const persistedReducer = persistReducer(persistConfig, rootReducer); | |
const composeEnhancers = (typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose; | |
/* export const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk))); */ | |
export const store = createStore(persistedReducer, composeEnhancers(applyMiddleware(thunk))); | |
export const persistor = persistStore(store); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment