Need an Example
See original GitHub issueDear maintainers, your library looks great but v5 just doesn’t work for me, I did read the readme and the only guide I’ve found. It just doesn’t write to my localStorage, here’s how I setup the store:
import { applyMiddleware, createStore } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';
const persistConfig = {
key: 'root',
storage: storage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const middlewares = [thunk];
let ehnancer = applyMiddleware(...middlewares);
const isDevMode = process.env.NODE_ENV === 'development';
if (isDevMode) {
const { composeWithDevTools } = require('redux-devtools-extension'); // eslint-disable-line global-require
ehnancer = composeWithDevTools(ehnancer);
}
const store = createStore(persistedReducer, undefined, ehnancer);
export default store;
export const persistor = persistStore(store);
Is it supposed to automatically persist when my store updates? I actually assumed that.
Please correct me if I’m missing something obvious, but I believe a working demo would solve anyone else’s problem of that kind. Does this make sense?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
The best 500 need sentence examples - YourDictionary
Need sentence example. He did not need anything of that kind. There was no need to rush. I am sorry, for I need...
Read more >How to Use Need with Example Sentences - English Collocation
Used with nouns: "They need money." ... "I need a shower." ... "She needs friendship." ... "She needs a favor." ... "He needs...
Read more >Needs: Definition and Examples
List of Basic Needs · Food · Water · Shelter · Clothing · Sunlight · Sleep.
Read more >English example sentences with "need" - Gikken
Learn how to use need in a English sentence. Over 100 hand-picked examples.
Read more >Needs: Definition, Example, Type - Penpoin
What's it: Needs means requiring something because it is essential. For example, we need food, water, and shelter to sustain our survival.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@grebenyuksv-preply sorry this has not been a straight forward integration for you! we are constantly working to improve the docs but it is a tough challenge.
I am glad you got it working. persistReducer should work as expected whether you apply it to the rootReducer or a nested reducer. There are a couple of things to look out for:
If you have suggestions for how to further improve the docs please share. I think (2) is the biggest gotcha that we are looking for ways to better communicate.
Thank you so much @Baransu , I did do this all before, but you inspired me for one more try. My setup didn’t seem to work for a combination of reasons:
const double = (state, { type }) => ({ value: Math.random() })
does not get persisted even if there are actions before the series ofpersist/REHYDRATE
;persist/PERSIST
andpersist/REHYDRATE
.Apparently, everything actually works, I think I’ll close this — but still, an example could save me a day. Maybe I’ll think of creating one.