@schema-render/core-react
Version:
Through a set of simple JSON Schema, efficiently build a set of forms.
41 lines (40 loc) • 1.1 kB
JavaScript
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Component } from "react";
import { isFunction } from "../utils/checking";
export default class ErrorBoundary extends Component {
static getDerivedStateFromError(error) {
return {
hasError: true,
error
};
}
state = {
hasError: false,
error: Error()
};
getFallback() {
const { error } = this.state;
const { catchErrorTips } = this.props;
if (catchErrorTips === 'silent') {
return null;
}
if (isFunction(catchErrorTips)) {
return catchErrorTips(error);
}
return /*#__PURE__*/ _jsxs("div", {
style: {
color: 'red'
},
children: [
"[ErrorBoundary] ",
(error === null || error === void 0 ? void 0 : error.stack) ?? String(error)
]
});
}
render() {
if (this.state.hasError) {
return this.getFallback();
}
return this.props.children;
}
}