Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react js error boundary functional component

// https://gist.github.com/andywer/800f3f25ce3698e8f8b5f1e79fed5c9c
import Catch from "./functional-error-boundary"

type Props = {
  children: React.ReactNode
}

const MyErrorBoundary = Catch(function MyErrorBoundary(props: Props, error?: Error) {
  if (error) {
    return (
      <div className="error-screen">
        <h2>An error has occured</h2>
        <h4>{error.message}</h4>
      </div>
    )
  } else {
    return <React.Fragment>{props.children}</React.Fragment>
  }
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #js #error #boundary #functional #component
ADD COMMENT
Topic
Name
1+6 =