@deep-foundation/deepcase
Version:
[](https://gitpod.io/#https://github.com/deep-foundation/deepcase) [](https://discord.gg/deep-
34 lines • 1.81 kB
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
export class CatchErrors extends React.Component {
constructor(props) {
super(props);
this.errorRenderer = (error, reset) => _jsx(_Fragment, {});
this.state = { error: undefined };
this.reset = () => {
var _a, _b;
this.setState({ error: undefined });
((_a = this === null || this === void 0 ? void 0 : this.props) === null || _a === void 0 ? void 0 : _a.reset) && ((_b = this === null || this === void 0 ? void 0 : this.props) === null || _b === void 0 ? void 0 : _b.reset());
};
}
static getDerivedStateFromError(error) {
console.log('getDerivedStateFromError', error);
return { error };
}
componentDidCatch(error, errorInfo) {
console.log('componentDidCatch', error, errorInfo);
}
componentDidMounted() {
var _a, _b;
((_a = this === null || this === void 0 ? void 0 : this.props) === null || _a === void 0 ? void 0 : _a.onMounted) && ((_b = this === null || this === void 0 ? void 0 : this.props) === null || _b === void 0 ? void 0 : _b.onMounted((error) => this.setState({ error: error })));
}
render() {
var _a, _b;
const error = this.props.error || this.state.error;
if (error) {
return ((_a = this === null || this === void 0 ? void 0 : this.props) === null || _a === void 0 ? void 0 : _a.errorRenderer) ? (_b = this === null || this === void 0 ? void 0 : this.props) === null || _b === void 0 ? void 0 : _b.errorRenderer(error, this.reset) : this === null || this === void 0 ? void 0 : this.errorRenderer(error, this.reset);
}
return this.props.children;
}
}
//# sourceMappingURL=react-errors.js.map