question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

persistStore's callback state is different than store.getState()

See original GitHub issue

My 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kormangcommented, Aug 23, 2017

Thanks for telling me, I’m on my way to change my code to make it future proof 😄

1reaction
rt2zzcommented, Aug 22, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found