简体   繁体   English

刷新浏览器时,Redux存储不会刷新(清除)

[英]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? 我的商店在F5ctrl+r上没有刷新(清除),我该如何解决这个问题? 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? 这是由于本地存储还是这是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. 我添加了一些features: {persist: false}因为persist: true, // persist states on page reloading是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) 您正在使用redux-persist lib(或其他一些lib将状态保存到localStorage或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 您还可以将存储保存到本地存储而不使用redux persist,这就是您应该检查在App.js中调用的函数的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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