gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:25:33 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com