Skip to content

Commit

Permalink
feat: [ErrorBoundary] support onError props
Browse files Browse the repository at this point in the history
  • Loading branch information
akai committed Jan 16, 2021
1 parent 4c1544d commit 9bb1b73
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type FallbackProps = ErrorBoundaryState;

export type ErrorBoundaryProps = {
FallbackComponent?: React.ComponentType<FallbackProps>;
onError?: (error: Error, info: React.ErrorInfo) => void;
[k: string]: any;
};

Expand All @@ -22,6 +23,10 @@ export class ErrorBoundary extends React.Component<
};

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
const { onError } = this.props;
if (onError) {
onError(error, errorInfo);
}
this.setState({ error, errorInfo });
}

Expand Down

0 comments on commit 9bb1b73

Please sign in to comment.