Managing React-Redux Error Pages

We have a response-redux project that we are trying to set up an error propagation mechanism and an error page display.

What we have done so far: when an error occurs in the asynchronous api call or somewhere else, we run the action and modify the application at the root level. In the root level reducer, we set the error field in the state with a common error. When an error is observed, we make a page with an error, and not the content that we have.

So, the stream is similar: Component A → Action → Reducer application → application component - Render errorPage.

But the problem is that the state remains with the error component. And since the error field remains in the state, the application continues to display the error page. We basically need a mechanism so that whenever a user starts a new action or whenever a page with an error is displayed, this will reset the error field to the state {}.

We could not find a good way to solve this problem. This seems like a very common one that anyone could come across earlier. In general, how can we handle the asynchronous error prediction and display the error page accordingly.

+4
source share
2 answers

The correct solution to this problem was to use:

componentWillUnmount() {
    this.props.handleErrorReset();
}

handleErrorReset , reset , - :

const clearErrorState = (state) => state.set('error', fromJS({}));

componentWillUnmount , , .

https://facebook.imtqy.com/react/docs/component-specs.html#unmounting-componentwillunmount

+2

, ​​ , , ), ​​.

+1

All Articles