mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +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;
|
|
}
|
|
}
|