@@ -48,11 +48,17 @@ export type ErrorBoundaryProps = {
48
48
beforeCapture ?( scope : Scope , error : Error | null , componentStack : string | null ) : void ;
49
49
} ;
50
50
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
+ } ;
56
62
57
63
const INITIAL_STATE = {
58
64
componentStack : null ,
@@ -133,18 +139,16 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
133
139
134
140
public render ( ) : React . ReactNode {
135
141
const { fallback, children } = this . props ;
136
- const { error , componentStack , eventId } = this . state ;
142
+ const state = this . state ;
137
143
138
- if ( error ) {
144
+ if ( state . error ) {
139
145
let element : React . ReactElement | undefined = undefined ;
140
146
if ( typeof fallback === 'function' ) {
141
147
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 ,
145
150
resetError : this . resetErrorBoundary ,
146
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147
- eventId : eventId ! ,
151
+ eventId : state . eventId ,
148
152
} ) ;
149
153
} else {
150
154
element = fallback ;
0 commit comments