Closed alexandrebouttier closed 3 years ago
@alexandrebouttier you should use a middleware and export like this -
const persistedReducer = persistReducer(persistConfig, rootReducers);
export const store = createStore(persistedReducer, applyMiddleware(thunk));
export const persistor = persistStore(store);
@alexandrebouttier you should use a middleware and export like this -
const persistedReducer = persistReducer(persistConfig, rootReducers); export const store = createStore(persistedReducer, applyMiddleware(thunk)); export const persistor = persistStore(store);
@mayank-budhiraja Thank you for your reply, I did like this but unfortunately it does not work
import { createStore, applyMiddleware } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import thunk from 'redux-thunk'
import rootReducer from './modules/reducer'
const persistConfig = {
key: 'root',
storage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
export const store = createStore(persistedReducer, applyMiddleware(thunk))
export const persistor = persistStore(store)
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { persistor, store } from './store/configureStore'
import { PersistGate } from 'redux-persist/integration/react'
import Router from './Router'
import './assets/stylesheets/index.scss'
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Router />
</PersistGate>
</Provider>,
document.getElementById('root')
)
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in window.navigator) {
window.onload = () => window.navigator.serviceWorker.register('/service-worker.js')
}
@mayank-budhiraja your solution has solved my basic problem, in fact my second problem is that I use firebase, and in fact even offline the promise goes into the then with their offline system, so I lose my data each time, thank you for your solution
Hello, I am having difficulty getting redux persist to work on my React app, persistence does not work when I cut my api nothing is kept in memory, if anyone has an idea
my file configureStore.js :
my file reducer.js :
An example of one of my modules : "entretiens.js"
my file index.js :