fix(core): make error boundary fallback a component instead of a callback (#7368)

This commit is contained in:
Joshua Chen 2022-05-07 22:35:57 +08:00 committed by GitHub
parent 77fa3d1470
commit f29bb73300
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 18 deletions

View file

@ -33,17 +33,13 @@ export default class ErrorBoundary extends React.Component<Props, State> {
const {error} = this.state;
if (error) {
const fallback = this.props.fallback ?? DefaultFallback;
return fallback({
error,
tryAgain: () => this.setState({error: null}),
});
const Fallback = this.props.fallback ?? DefaultFallback;
return (
<Fallback error={error} tryAgain={() => this.setState({error: null})} />
);
}
return (
children ??
// See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
null
);
// See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
return children ?? null;
}
}