【问题标题】:Delete or Reset redux thunk store completely while logout注销时完全删除或重置 redux thunk store
【发布时间】:2021-09-08 15:08:04
【问题描述】:

我在我的 react native 项目中使用redux, react-redux and redux thunk 管理store,有不同的reducersactions。我在注销期间如何reset 整个store

有没有像createStore() 这样的方法来销毁商店? 请分享可能的解决方案

谢谢

【问题讨论】:

  • 您可以创建还原器来恢复初始状态,或者如果您将状态存储在 AynscStorage 上,您可以使用键清除状态:persist:root。
  • 您是否尝试过刷新页面?
  • @kunquan 是的尝试过,如果再次调用 api 然后重置值但是,如果我没有调用 api 那么我正在获取以前的用户数据,我想在注销期间销毁存储
  • 这能回答你的问题吗? How to reset the state of a Redux store?

标签: reactjs react-native redux react-redux redux-thunk


【解决方案1】:

以下解决方案对我有用,

import reduxReset from 'redux-reset'

const enHanceCreateStore = compose(
    applyMiddleware(thunk),
    reduxReset()  
  )(createStore)

const store = enHanceCreateStore(reducers)

调度重置操作

store.dispatch({
  type: 'RESET'
})

【讨论】:

    猜你喜欢
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多