UNPKG

@winglet/react-utils

Version:

React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality

33 lines (29 loc) 844 B
'use strict'; var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); var FallbackMessage = require('./FallbackMessage.cjs'); const FALLBACK = jsxRuntime.jsx(FallbackMessage.FallbackMessage, {}); class ErrorBoundary extends react.Component { constructor(props) { super(props); this.state = { hasError: false, error: undefined, }; } static getDerivedStateFromError(error) { return { hasError: true, error, }; } componentDidCatch(error, errorInfo) { console.error('ErrorBoundary caught an error:', error, errorInfo); } render() { if (this.state.hasError) return this.props.fallback || FALLBACK; return this.props.children; } } exports.ErrorBoundary = ErrorBoundary;