ant-design/site/theme/template/Content/ErrorBoundary.js

23 lines
515 B
JavaScript
Raw Normal View History

2018-08-02 18:10:59 +08:00
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;
}
}