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