@arolariu/components
Version:
🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡
61 lines (60 loc) • 2.13 kB
JavaScript
"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import error_boundary_module from "./error-boundary.module.js";
import * as __rspack_external_react from "react";
class ErrorBoundary extends __rspack_external_react.Component {
static getDerivedStateFromError(error) {
return {
error
};
}
static{
this.displayName = "ErrorBoundary";
}
constructor(props){
super(props), this.handleReset = ()=>{
this.setState({
error: null
});
};
this.state = {
error: null
};
}
shouldComponentUpdate(nextProps, nextState) {
const { children, fallback, onError } = this.props;
const { error } = this.state;
return nextProps.children !== children || nextProps.fallback !== fallback || nextProps.onError !== onError || nextState.error !== error;
}
componentDidCatch(error, errorInfo) {
const { onError } = this.props;
onError?.(error, errorInfo);
}
render() {
const { error } = this.state;
const { children, fallback } = this.props;
const content = null === error ? children : "function" == typeof fallback ? fallback(error, this.handleReset) : fallback ?? /*#__PURE__*/ jsxs("div", {
className: error_boundary_module.fallback,
role: "alert",
children: [
/*#__PURE__*/ jsx("p", {
className: error_boundary_module.title,
children: "Something went wrong"
}),
/*#__PURE__*/ jsx("p", {
className: error_boundary_module.message,
children: error.message
}),
/*#__PURE__*/ jsx("button", {
type: "button",
className: error_boundary_module.retry,
onClick: this.handleReset,
children: "Try again"
})
]
});
return content;
}
}
export { ErrorBoundary };
//# sourceMappingURL=error-boundary.js.map