treeherder/ui/shared/ErrorBoundary.jsx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 строки
878 B
React
Исходник Постоянная ссылка Обычный вид История

2018-08-31 20:53:45 +03:00
import React from 'react';
import PropTypes from 'prop-types';
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {
hasError: false,
error: null,
};
}
componentDidCatch(error) {
this.setState({
hasError: true,
error,
});
}
render() {
const { children, errorClasses, message } = this.props;
const { hasError, error } = this.state;
if (hasError) {
return (
<span className={errorClasses}>
{message} {error.toString()}
</span>
);
2018-08-31 20:53:45 +03:00
}
return children;
}
}
ErrorBoundary.propTypes = {
children: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
2018-08-31 20:53:45 +03:00
errorClasses: PropTypes.string,
message: PropTypes.string,
};
ErrorBoundary.defaultProps = {
errorClasses: '',
message: '',
children: null,
2018-08-31 20:53:45 +03:00
};