nextjs-demo

next.js demo using react 19 rc

git clone https://9o.is/git/nextjs-demo.git

ErrorBoundary.tsx

(803B)


      1 import React, { ReactNode } from "react"
      2 import { Alert } from "./headless/Alert"
      3 
      4 type ErrorBoundaryProps = {
      5     children: ReactNode
      6 }
      7 
      8 type ErrorBoundaryState = {
      9     error?: Error
     10 }
     11 
     12 export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
     13     
     14     constructor(props: ErrorBoundaryProps) {
     15         super(props)
     16         this.state = {}
     17     }
     18 
     19     static getDerivedStateFromError(error: Error): ErrorBoundaryState {   
     20         return { error }
     21     }
     22 
     23     componentDidCatch(error: any, errorInfo: any) {
     24         console.log('error boundaary', { error, errorInfo })
     25     }
     26 
     27     render() {
     28         const { error } = this.state
     29         const { children } = this.props
     30 
     31         return (
     32             <>
     33                 {/* {children} */}
     34             </>
     35         )
     36     }
     37 }