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.

Usage with redux-persist

See original GitHub issue

How would I use this with redux-persist?

  // routesMap.js
  …
  WALLET_SELECTOR: {
    path: '/wallet-selector/:currency',
    thunk: (dispatch, getState) => {

       // I don't seem to have the rehydrated state here.
       // Is it somehow possible to 'await' rehydration here?
      const { steps } = getState()

      canContinueIf(steps.currencySelected, dispatch)
    }
  },
  …

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
ganlubcommented, Aug 16, 2017

@faceyspacey I ended up going with the initialDispatch: false, I wasn’t aware of this property, so I removed the redux-action-buffer because it’s not needed at all.

In case it helps somebody, persistStore allows you to add a callback when the re-hydration is complete, so there you can call initialDispatch(). There’s as well a gap of a few milliseconds while all of this happens, so I added a spinner so it won’t render a blank screen. I have a page reducer (I took this approach from the official demo) and I set the initial state like this:

export default (state = LOADING, action = {}) => {
  return components[action.type] || state
}

const components = {
  ROUTE_HOME,
  ROUTE_LOGIN,
  NOT_FOUND
}
2reactions
brownbl1commented, Aug 16, 2017

Not to worry though. Seems like the callback behavior is coming back: https://github.com/rt2zz/redux-persist/issues/408

Read more comments on GitHub >

github_iconTop Results From Across the Web

Persist Redux State with redux-persist - DEV Community ‍ ‍
redux -persist provides different storage to persist data like local storage, session storage or async storge. We will use the local storage. We ......
Read more >
The Definitive Guide to Redux Persist - React Native Coach
Redux Persist takes your Redux state object and saves it to persisted storage. Then on app launch it retrieves this persisted state and...
Read more >
How To Use Redux Persist In React Application
Redux persist takes your Redux state object and save it to Persistence storage. For example, If we store your redux reducers using redux...
Read more >
Usage Guide - Redux Toolkit
Usage Guide. The Redux core library is deliberately unopinionated. It lets you decide how you want to handle everything, like store setup, ...
Read more >
Why use redux-persist over manually persisting state to ...
Usage of PersistGate which automatically provides a delay in rendering of the components until the state gets persisted along with the usage to ......
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