@datalayer/primer-rjsf
Version:
React JSON Schema Form (RJSF) for Primer
24 lines (23 loc) • 995 B
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
}
/** Update state so the next render will show the fallback UI. */
static getDerivedStateFromError(error) {
return { hasError: true, error: error };
}
resetErrorBoundary = () => {
this.setState({ hasError: false, error: null });
};
/** You can render any custom fallback UI */
render() {
if (this.state.hasError) {
return (_jsxs("div", { className: "alert alert-danger", children: [_jsx("p", { children: "The following error was encountered:" }), _jsx("pre", { children: this.state.error.message }), _jsx("button", { className: "btn", onClick: this.resetErrorBoundary, children: "Refresh Form" })] }));
}
return this.props.children;
}
}
export default ErrorBoundary;