-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorBoundary.tsx
35 lines (32 loc) · 1.01 KB
/
ErrorBoundary.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from 'react';
import * as Sentry from '@sentry/browser';
import { Alert } from 'react-native';
import RNRestart from 'react-native-restart';
export class ErrorBoundary extends React.PureComponent<{ children: unknown }> {
state = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidMount() {
Sentry.init({
dsn: 'https://[email protected]/5222763',
});
}
componentDidCatch(error: Error) {
Sentry.captureException(error);
Alert.alert(
'Unexpected error',
'This error has been forward to the developer. Please restart to continue.',
[
{
text: 'Restart App',
onPress: () => RNRestart.Restart(),
},
],
{ cancelable: false },
);
}
render() {
return this.state.hasError ? null : this.props.children;
}
}