简体   繁体   中英

Redux store does not refresh(clear) on refreshing the browser

My store does not refresh(clear) on F5 or ctrl+r , how do I go about solving this issue? I can see it being beneficial in some scenarios to keep the state on refresh, but that does not work for my case. Is this due to local storage or is this the intended behavior of redux?

This is the current store setup:

const composeEnhancers =
  typeof window === 'object' &&
  (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
    ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
        serialize: true,
        latency: 0
      })
    : compose;

const createStoreWithApi = (api: IApi, initialState?: {})  => {
  const middlewares = [
    thunkMiddleware.withExtraArgument({
      api
    })
  ];
  const enhancer = composeEnhancers(applyMiddleware(...middlewares));
  return createStore(rootReducer, initialState!, enhancer);
};

EDIT:

Solved this issue thanks to the comment. I added features: {persist: false} because persist: true, // persist states on page reloading is the default behavior in redux-devtools-extension.


 (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ serialize: true, latency: 0, features: {persist: false} })

I can think of 2 options:

  • You are using the redux-persist lib (or some other lib saving the state into the localStorage or cookies)
  • There is some syncing process from the server side

Try to clear your local storage manually. Then check the behavior of your project. You also can save store to local storage without redux persist, that is why you should check functions that calls in App.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM