reactjs - 如何清除componentWillUnmount中组件存储的redux状态?

标签 reactjs react-redux

We are storing the data for the particular component in the redux store by using creatStore() and where combining all the component's state by using combineReducers().Now Once we came out of the page we need to clear the state stored using redux. This is not the dublicate question as written in How should I clear state in componentWillUnmount? because in this question they want to clear the state of the page that they save by using this.state{}.In our scenario we have to clean from global state (redux-stored-state) for the particular component.We want a global solution so that we can apply to all our component.Please assist me.

最佳答案

您可以在 componentWillUnmount 中分派(dispatch)一个 reset 操作,该操作将由相应的 reducer 处理。 reducer 将清除 redux 状态。

为了使其全局化,您可以创建一个高阶组件,将重置操作的分派(dispatch)添加到它所应用到的组件。您可以为整个应用程序使用一个 reducer 来处理重置操作。

关于reactjs - 如何清除componentWillUnmount中组件存储的redux状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510651/

相关文章:

javascript - react-redux Provider 在 IE 10/11 中给出错误 “onlyChild must be passed a children with exactly one child”

javascript - Nextjs 将数据(页面标题)发送到组件

javascript - 正确卸载 React 组件

javascript - 如何使用 MUI React 左对齐 Item1 并右对齐 Item2 和 Item3?

javascript - 由于凭据无效,Sabre API GET 请求失败

css - 通过 json 数据 react 原生动态主题

ios - 将 react-native-router-flux 与 redux 一起使用,如何更新 View 组件中的状态?

javascript - 分派(dispatch)操作和状态更新时组件不重新渲染

javascript - 单击同一提交按钮以 react-redux 形式更新状态和 Prop

javascript - Nextjs useEffect 和 useState Hook 不适用于生产