/ src / components / SentryErrorBoundary.ts
SentryErrorBoundary.ts
 1  import * as React from 'react'
 2  import { captureException } from '../services/sentry.js'
 3  
 4  interface Props {
 5    children: React.ReactNode
 6  }
 7  
 8  interface State {
 9    hasError: boolean
10  }
11  
12  export class SentryErrorBoundary extends React.Component<Props, State> {
13    constructor(props: Props) {
14      super(props)
15      this.state = { hasError: false }
16    }
17  
18    static getDerivedStateFromError(): State {
19      return { hasError: true }
20    }
21  
22    componentDidCatch(error: Error): void {
23      captureException(error)
24    }
25  
26    render(): React.ReactNode {
27      if (this.state.hasError) {
28        return null
29      }
30  
31      return this.props.children
32    }
33  }