@plone/volto
Version:
Volto
30 lines (23 loc) • 659 B
JSX
import React from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
// eslint-disable-next-line
console.error(error, errorInfo);
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <pre className="error">{`<error: ${this.props.name}>`}</pre>;
}
return this.props.children;
}
}
export default ErrorBoundary;