File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ "use client" ;
2+ import { Component , ReactNode } from "react" ;
3+
4+ type Props = {
5+ children : ReactNode ;
6+ } ;
7+
8+ type State = {
9+ hasError : boolean ;
10+ } ;
11+
12+ export class ErrorBoundary extends Component < Props , State > {
13+ constructor ( props : Props ) {
14+ super ( props ) ;
15+ this . state = { hasError : false } ;
16+ }
17+
18+ static getDerivedStateFromError ( _ : Error ) {
19+ return { hasError : true } ;
20+ }
21+
22+ componentDidCatch ( error : Error , info : any ) {
23+ console . error ( "Caught by ErrorBoundary:" , error , info ) ;
24+ }
25+
26+ render ( ) {
27+ if ( this . state . hasError ) {
28+ return (
29+ < main style = { { padding : "2rem" , textAlign : "center" } } >
30+ < h1 > Something went wrong.</ h1 >
31+ < p > Try refreshing the page. If the problem persists, please report it.</ p >
32+ </ main >
33+ ) ;
34+ }
35+
36+ return this . props . children ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments