guild_front/src/hoc/ErrorBoundary.js

22 lines
393 B
JavaScript
Raw Normal View History

2023-01-18 17:37:52 +03:00
import React, {Component} from "react";
class ErrorBoundary extends Component {
state = {
error: null,
};
static getDerivedStateFromError(error) {
return {error};
}
render() {
const { error } = this.state;
if (error) {
return <div>Что-то пошло не так =( {error}</div>;
}
return this.props.children;
}
}
export default ErrorBoundary