persistStore's callback state is different than store.getState()
See original GitHub issueMy init function runs each time my react native app is launched. On first launch, this parameter is an empty object. However, I was expecting all of the default values as declared in my reducer. What’s the intended/recommended way to use that ‘state’ parameter?
import init from '../init';
...
persistStore(AppStore, { storage: AsyncStorage }, init);
// init.js
export default (err, state) => {
// state from function param is an empty object on first launch
// But state from store.getState() has the default values from my reducer
stateFromStore = AppStore.getState();
...
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Redux persist rehydrate previous auth state too late
The persistStore function which is used to make your store persistent have a third param callback which is invoked after store rehydration ...
Read more >Usage Guide - Redux Toolkit
It lets you decide how you want to handle everything, like store setup, what your state contains, and how you want to build...
Read more >redux-persist - npm
remove all arguments from the callback. If you need state you can call store.getState(). all constants (ex: REHYDRATE , PURGE ) has moved ......
Read more >Top 5 redux-persist Code Examples - Snyk
enhancers)); const persistor = persistStore(store, persistConfig, () => { // console.log('Test', store.getState()); }); const configureStore = () => { return { ...
Read more >Creating React Apps With Redux Toolkit and RTK Query - Toptal
Have you ever wanted to use Redux with features like React Query provides? ... export const persistor = persistStore(store); export type ...
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
Thanks for telling me, I’m on my way to change my code to make it future proof 😄
ya this is a bit confusing and should be documented. in v5 the callback does not receive any arguments so it will no longer be an issue. In v5 you will either call
store.getState()
if needed or if you need the intermediary state you can implement a migration.