How do I clear the state of a stored component in component WillUnmount?

We store data for a particular component in a reduction store using creatStore () and combine all components using combReducers (). Now that we're out of the page, we need to clear the state saved with redux. This is not a duplicate question, as written in How do I clear the state in the WillUnmount component? because in this question they want to clear the page state that they are persisting with this.state {}. In our scenario, we have to clear the global state (abbreviated-saved state) for a specific component. We want a global solution so that we can refer to our entire component. Please help me.

+3


source to share


1 answer


You can dispatch an action reset

to componentWillUnmount

which will be handled by the appropriate reducer. The reducer will clear the reduction state.



To make it global, you can create a higher-order component that will add dispatching the reset action to the component it applied to. And you can have one reducer for the whole application to handle reset actions.

+7


source







All Articles