Skip to content

Commit

Permalink
Remove setState call from ErrorBoundary render fn
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Aug 30, 2023
1 parent 6f4073b commit 02f4d7a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/module/src/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,24 @@ class ErrorBoundary extends React.Component<React.PropsWithChildren<ErrorPagePro
return { hasError: true, error, historyState: history.state };
}

render() {

updateState = () => {
if (this.state.historyState !== history.state) {
this.setState({
hasError: false,
historyState: history.state,
});
}
};

componentDidUpdate(): void {
this.updateState();
}

componentDidMount(): void {
this.updateState();
}

render() {
if (this.state.hasError) {
if (this.props.silent) {
return null;
Expand Down

0 comments on commit 02f4d7a

Please sign in to comment.