File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22import { ApolloProvider } from '@apollo/react-hooks'
33
4+ import ErrorBoundary from './components/ErrorBoundary'
45import client from './services/apollo'
56import Routes from './Routes'
67
78const App = ( ) => (
8- < ApolloProvider client = { client } >
9- < Routes />
10- </ ApolloProvider >
9+ < ErrorBoundary >
10+ < ApolloProvider client = { client } >
11+ < Routes />
12+ </ ApolloProvider >
13+ </ ErrorBoundary >
1114)
1215
1316export default App
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+
3+ class ErrorBoundary extends React . Component {
4+ public state = { hasError : false }
5+
6+ public componentDidCatch ( 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+ public render ( ) {
15+ if ( this . state . hasError ) {
16+ // You can render any custom fallback UI
17+ return < h1 > Something went wrong.</ h1 >
18+ }
19+ return this . props . children
20+ }
21+ }
22+
23+ export default ErrorBoundary
You can’t perform that action at this time.
0 commit comments