Open tilakgajjar opened 6 years ago
Yeah, I'm struggling with this as well. I think it has something to do with ImmutableJS. In previous redux-persist
versions we used to have redux-persist-immutable
library to persistStore
but now it's not usable in this version.
Any updates on this issue I am facing the same issue. any solution?
@Farrukhameen ended up using version 4. At least it works as expected.
I implemented redux persist with this:
https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
@Gyvastis version 4 of redux-persist or what ?
@sincerekamal version 4 of redux-persist works with react-boilerplate
Is there any documentation for that specifically ? because I failed to do it correctly. It would be great to just integrating this into react-boilerplate
For my build
redux-persist@4.10.2
(documentation)redux-persist-immutable@4.3.1
Relevant code in store.js
import { persistStore, autoRehydrate } from 'redux-persist-immutable';
import localForage from 'localforage';
// ...
const enhancers = [
applyMiddleware(...middlewares),
autoRehydrate(),
];
// ...
const store = createStore(
createReducer(),
fromJS(initialState),
composeEnhancers(...enhancers)
);
window.persistor = persistStore(store, { storage: localForage, whitelist: [/*app-specific keys*/] }, (a, b) => {
console.log('Redux-Persist loaded state');
});
store.runSaga = sagaMiddleware.run;
store.injectedReducers = {};
store.injectedSagas = {};
// ...
I have more related code but its app-specific. That should be enough to get it working.
EDIT: I assign it to windows.persistor
because I want to stop persisting/purge based on user actions later in the app and I couldn't find an easier way to access the persistor. works fine when assigned to window
obviously you use also https://www.npmjs.com/package/localforage. Anyway I´m new to react/redux and don´t see how to merge this with https://www.npmjs.com/package/redux-persist. The docu on https://www.npmjs.com/package/redux-persist-immutable says it`s a wrapper so some of the original redux-persist need still to be applied, but seams to be incompatible. For eg:
const persistedReducer = persistReducer(persistConfig, rootReducer)
I´m also not sure weather or not once can use the window.persistor like that:
const App = () => {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={window.persistor}>
<RootComponent />
</PersistGate>
</Provider>
);
};
When it try this I get the exception:
react.js?28cc:53 Uncaught TypeError: this.props.persistor.subscribe is not a function
at PersistGate.componentDidMount (react.js?28cc:53)
at commitLifeCycles (react-dom.development.js:14361)
at commitAllLifeCycles (react-dom.development.js:15462)
at HTMLUnknownElement.callCallback (react-dom.development.js:100)
at Object.invokeGuardedCallbackDev (react-dom.development.js:138)
at invokeGuardedCallback (react-dom.development.js:187)
at commitRoot (react-dom.development.js:15603)
at completeRoot (react-dom.development.js:16618)
at performWorkOnRoot (react-dom.development.js:16563)
at performWork (react-dom.development.js:16482)
and I´m not the only one: https://github.com/rt2zz/redux-persist/issues/731 A working full example would be great.
localforage was my choice for storage engine yes, but any of the options from the docs can be used.
Redux Persist 5 is a mess. The majority of issues on this repo were created after the release of v5. And no real commits addressing issues have been made since at least June 2018. I tried migrating to v5 on release it was never worked.
I would suggest you stick to the version I mentioned in my comment unless there is something specific you need with v5.
you are damn right its a mess, just look at this: https://github.com/rt2zz/redux-persist/issues/64 Thanks for the fast reply, I´ll try to find some old documentation for v4 and stick to that.
Thx!
It is a mess. If anybody wants to help with development, bug fixes, or organizing the issues, help would surely be very welcome. I'm trying to at least organize and prioritize the issues with labels, and work through all the old ones. I think @rt2zz has very limited time to spend working on redux-persist, but maybe he could chime in.
when no need of redux-persist
and want to persist you can do this as well: https://github.com/rt2zz/redux-persist/issues/581#issuecomment-491964148
Anyone knows any solution on this? I know the issue is for like 2 years ago but I couldn't find any way to persist my redux state. Clearly redux-persist is not a solution. I tried to implement it my self using local storage but because the reducers are not loaded in the first place I get this error:
Unexpected keys "App", "User" found in preloadedState argument passed to createStore
So what should I do? I have written lots of codes using react-boilerplate
approach and now the persisting seems impossible :/
@erfansamieyan The thing I've seen mentioned most often, which we haven't done in our code yet because it's all redux-persisted and I'm scared to touch it, is this: https://medium.com/@jrcreencia/persisting-redux-state-to-local-storage-f81eb0b90e7e I've seen multiple smart people say "just throttle it to save once per second" as demonstrated there.
Let me know how it turns out... we might do this soon in my app.
@erfansamieyan my project is using slightly modified react-boilerplate that is as current as november 2019, my persist setup is still the same as my comment above https://github.com/rt2zz/redux-persist/issues/815#issuecomment-408876514 and still works
configureStore.js
reducers.js
app.js
[
](url)