UNPKG

@deep-foundation/deepcase

Version:

[![Gitpod](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/deep-foundation/deepcase) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label&color=purple)](https://discord.gg/deep-

34 lines 1.81 kB
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