mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-26 18:08:34 +08:00
23 lines
515 B
JavaScript
23 lines
515 B
JavaScript
import React from 'react';
|
|
import { Alert } from 'antd';
|
|
|
|
export default class ErrorBoundary extends React.Component {
|
|
state = {
|
|
error: null,
|
|
};
|
|
|
|
componentDidCatch(error, info) {
|
|
this.setState({ error, info });
|
|
}
|
|
|
|
render() {
|
|
const { children } = this.props;
|
|
const { error, info } = this.state;
|
|
if (error) {
|
|
// You can render any custom fallback UI
|
|
return <Alert type="error" message={error.toString()} description={info.componentStack} />;
|
|
}
|
|
return children;
|
|
}
|
|
}
|