UNPKG

@kwiz/fluentui

Version:
33 lines 1.2 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { CommonLogger } from "@kwiz/common"; import * as React from "react"; const logger = new CommonLogger("ErrorBoundary"); export class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, marker: props.changeMarker }; } static getDerivedStateFromError(error) { // Update state so the next render will show the fallback UI. return { hasError: true }; } static getDerivedStateFromProps(props, state) { if (props.changeMarker !== state.marker) return { hasError: false, marker: props.changeMarker }; else return null; } componentDidCatch(error, errorInfo) { // You can also log the error to an error reporting service logger.i.error(error); logger.i.error(errorInfo); } render() { if (this.state.hasError) { // You can render any custom fallback UI return this.props.errorComponent || _jsx("h1", { children: "Something went wrong." }); } return this.props.children; } } //# sourceMappingURL=error-boundary.js.map