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.

prevent persist/REHYDRATE on new page

See original GitHub issue

Hello,

I’m not sure if this is an Issue but I didn’t found a soultion.

If I go from the root page to a new route for example /suche the “persist/REHYDRATE” event is fired. It shouldn’t since in my case the state should be the same for all routes.

Hope someone can help or look over it. Or give me an idea how solve it. I could try to catch the event in all the reducers but it isn’t a nice solution!

Thats is my setup:

import React from 'react';
import {render} from 'react-dom';
import Home from './components/Home';
import Suche from './components/Suche';
import WohnungView from './components/WohnungView';
import Impressum from './components/Impressum';
import Datenschutz from './components/Datenschutz';
import NotFound404 from './components/NotFound404';
import {Router, Route, browserHistory, Redirect} from 'react-router';
import {persistStore, autoRehydrate} from 'redux-persist'
import {Provider} from 'react-redux';
import {compose,createStore, applyMiddleware} from 'redux';
import reducers from './reducers';
import thunkMiddleware  from 'redux-thunk';
import promiseMiddleware from 'redux-promise-middleware';
import localForage from "localforage";


export const store = createStore(
    reducers,
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
    compose(
        applyMiddleware(
            thunkMiddleware,
            promiseMiddleware()),
        autoRehydrate()
    )
);
const persistor = persistStore(store, {storage: localForage});
render(
    <Provider store={store} persistor={persistor}>
        <Router history={browserHistory}>
            <Route path="/" component={Home}/>
            <Route path="/suche" component={Suche}/>
            <Route path="/wohnung/:id" component={WohnungView}/>
            <Route path="/Impressum" component={Impressum}/>
            <Route path="/Datenschutz" component={Datenschutz}/>
            <Route path="*" component={NotFound404} />
        </Router>
    </Provider>,
    document.getElementById('root')
);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rt2zzcommented, Aug 19, 2017

@MichaelRazum why are you calling persistStore inside of the Banner component? typically you would only call persistStore once in your root module, like you have in your OP. Removing persistStore from Banner should resolve it issue.

0reactions
MichaelRazumcommented, Aug 20, 2017

@rt2zz Thanks a lot for the help. I was not that familiar with the framework and copy and pasted a solution where the component waits till render is finished. Since only the banner should wait before it renders I placed that part of the code to the banner. Wasn’t aware that that can cause problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop redux-form's "form" state from auto-rehydrated by ...
I have a "perfect" solution based on suggestion by @jpdelatorre from this thread How to handle redux-form/CHANGE in reducer.
Read more >
Redux-Persist: How it Works and How to Change the Structure ...
This article focus on Redux-persist persistence steps and how to modify persistence state with migrations and createMigrate function.
Read more >
Advanced topics on caching in Apollo Client
You can persist and rehydrate the InMemoryCache from a storage provider like AsyncStorage or localStorage . To do so, use the apollo3-cache-persist library....
Read more >
Top 5 redux-persist Code Examples - Snyk
Learn more about how to use redux-persist, based on redux-persist code examples ... reducers to avoid them to persist, so call // persistStore(...
Read more >
7 - Persisting Redux Store - Building a Contact Management ...
This is the 7th part of the Building a Contact Management System With React and Ant Design Library.This lesson concentrates on persisting ......
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