@@ -48,11 +48,17 @@ export type ErrorBoundaryProps = {
4848 beforeCapture ?( scope : Scope , error : Error | null , componentStack : string | null ) : void ;
4949} ;
5050
51- type ErrorBoundaryState = {
52- componentStack : React . ErrorInfo [ 'componentStack' ] | null ;
53- error : Error | null ;
54- eventId : string | null ;
55- } ;
51+ type ErrorBoundaryState =
52+ | {
53+ componentStack : null ;
54+ error : null ;
55+ eventId : null ;
56+ }
57+ | {
58+ componentStack : React . ErrorInfo [ 'componentStack' ] ;
59+ error : Error ;
60+ eventId : string ;
61+ } ;
5662
5763const INITIAL_STATE = {
5864 componentStack : null ,
@@ -133,18 +139,16 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
133139
134140 public render ( ) : React . ReactNode {
135141 const { fallback, children } = this . props ;
136- const { error , componentStack , eventId } = this . state ;
142+ const state = this . state ;
137143
138- if ( error ) {
144+ if ( state . error ) {
139145 let element : React . ReactElement | undefined = undefined ;
140146 if ( typeof fallback === 'function' ) {
141147 element = fallback ( {
142- error,
143- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
144- componentStack : componentStack ! ,
148+ error : state . error ,
149+ componentStack : state . componentStack ,
145150 resetError : this . resetErrorBoundary ,
146- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147- eventId : eventId ! ,
151+ eventId : state . eventId ,
148152 } ) ;
149153 } else {
150154 element = fallback ;
0 commit comments