UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

11 lines (9 loc) • 789 B
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import{Component as r}from"react";import{jsx as o}from"react/jsx-runtime";class t extends r{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(r,o){this.props.onError(r instanceof Error?r:new Error(String(r),{cause:r}),o)}render(){return this.state.hasError?this.props.fallback:this.props.children}}function e({children:r,fallback:e,onError:n}){ return o(t,{fallback:void 0===e?/*#__PURE__*/o("div",{style:{border:"1px solid #f00",color:"#f00",padding:"8px"},children:"An error was thrown."}):e,onError:n,children:r})}export{e as LexicalErrorBoundary};