Redux-persist: How to use PersistGate with react-router-dom?

Created on 27 Apr 2018  路  2Comments  路  Source: rt2zz/redux-persist

PersistGate is a PureComponent, so children doesn't rerender, when location changed with react-router-dom

Example: https://stackblitz.com/edit/redux-persist

Most helpful comment

PersistGate and Provider need to go outside of ReactRouter:

export default () => (
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <Router history={history}>
        <App />
      </Router>
    </PersistGate>
  </Provider>
);

All 2 comments

I have found some solution:

const PersistGateWithRouter = withRouter(PersistGate);

But maybe PersistGate doesn't need to be a pure?

PersistGate and Provider need to go outside of ReactRouter:

export default () => (
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <Router history={history}>
        <App />
      </Router>
    </PersistGate>
  </Provider>
);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssorallen picture ssorallen  路  4Comments

ejbp picture ejbp  路  3Comments

admbtlr picture admbtlr  路  3Comments

rturk picture rturk  路  3Comments

thenewt15 picture thenewt15  路  3Comments