2
votes

I have an application that creates a new record and redirect the history to the new record page using react-redux-router push. This redirection is made by a "smart component" inside another smart component.

The state of these components is stored on a redux store.

After redirection if I go back to the previous page it's state is dirty. Is there a way to reset the state ? Or should I manually clean it up before the redirection.

Currently I'm listening on the reducer for LOCATION_CHANGE and resetting it but this seems manual and hacky. Shouldn't the component unmount when it's route is not rendered anymore?

1

1 Answers

2
votes

I'm unclear from your question - is the state that you're wanting to be reset stored within that component (setState) or within the Redux store?

If it's within that component, and the component is unmounted, then its state should be automatically reset.

If it's within the Redux store, then the whole point of the Redux store is that it exists persistently, outside of whatever components are mounted. One common way of resetting state in that case would be to dispatch a clear or reset action within the component's componentWillMount (i.e., the component ensures that it always starts with a good state).