Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit139eafb

Browse files
committed
add ui error boundary
1 parent3a172c5 commit139eafb

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

‎web-app/src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import*asReactfrom'react'
22
import{ApolloProvider}from'@apollo/react-hooks'
33

4+
importErrorBoundaryfrom'./components/ErrorBoundary'
45
importclientfrom'./services/apollo'
56
importRoutesfrom'./Routes'
67

78
constApp=()=>(
8-
<ApolloProviderclient={client}>
9-
<Routes/>
10-
</ApolloProvider>
9+
<ErrorBoundary>
10+
<ApolloProviderclient={client}>
11+
<Routes/>
12+
</ApolloProvider>
13+
</ErrorBoundary>
1114
)
1215

1316
exportdefaultApp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import*asReactfrom'react'
2+
3+
classErrorBoundaryextendsReact.Component{
4+
publicstate={hasError:false}
5+
6+
publiccomponentDidCatch(error:Error,info:any){
7+
// Display fallback UI
8+
this.setState({hasError:true})
9+
// You can also log the error to an error reporting service
10+
console.error(error)
11+
console.log(info)
12+
}
13+
14+
publicrender(){
15+
if(this.state.hasError){
16+
// You can render any custom fallback UI
17+
return<h1>Something went wrong.</h1>
18+
}
19+
returnthis.props.children
20+
}
21+
}
22+
23+
exportdefaultErrorBoundary

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp