1. // Example
    
  2. 
    
  3. const x = React.createElement;
    
  4. 
    
  5. class ErrorBoundary extends React.Component {
    
  6.   static getDerivedStateFromError(error) {
    
  7.     return {
    
  8.       error: error,
    
  9.     };
    
  10.   }
    
  11. 
    
  12.   componentDidCatch(error, errorInfo) {
    
  13.     console.log(error.message, errorInfo.componentStack);
    
  14.     this.setState({
    
  15.       componentStack: errorInfo.componentStack,
    
  16.     });
    
  17.   }
    
  18. 
    
  19.   render() {
    
  20.     if (this.state && this.state.error) {
    
  21.       return x(
    
  22.         'div',
    
  23.         null,
    
  24.         x('h3', null, this.state.error.message),
    
  25.         x('pre', null, this.state.componentStack)
    
  26.       );
    
  27.     }
    
  28.     return this.props.children;
    
  29.   }
    
  30. }
    
  31. 
    
  32. function Example() {
    
  33.   let state = React.useState(false);
    
  34.   return x(
    
  35.     ErrorBoundary,
    
  36.     null,
    
  37.     x(
    
  38.       DisplayName,
    
  39.       null,
    
  40.       x(
    
  41.         React.unstable_SuspenseList,
    
  42.         null,
    
  43.         x(
    
  44.           NativeClass,
    
  45.           null,
    
  46.           x(
    
  47.             FrozenClass,
    
  48.             null,
    
  49.             x(
    
  50.               BabelClass,
    
  51.               null,
    
  52.               x(
    
  53.                 BabelClassWithFields,
    
  54.                 null,
    
  55.                 x(
    
  56.                   React.Suspense,
    
  57.                   null,
    
  58.                   x('div', null, x(Component, null, x(Throw)))
    
  59.                 )
    
  60.               )
    
  61.             )
    
  62.           )
    
  63.         )
    
  64.       )
    
  65.     )
    
  66.   );
    
  67. }