@@ -13,8 +13,8 @@ export const UNKNOWN_COMPONENT = 'unknown';
13
13
14
14
export type FallbackRender = ( errorData : {
15
15
error : Error ;
16
- componentStack : string | null ;
17
- eventId : string | null ;
16
+ componentStack : string ;
17
+ eventId : string ;
18
18
resetError ( ) : void ;
19
19
} ) => React . ReactElement ;
20
20
@@ -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,12 +139,17 @@ 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
- element = fallback ( { error, componentStack, resetError : this . resetErrorBoundary , eventId } ) ;
147
+ element = fallback ( {
148
+ error : state . error ,
149
+ componentStack : state . componentStack ,
150
+ resetError : this . resetErrorBoundary ,
151
+ eventId : state . eventId ,
152
+ } ) ;
142
153
} else {
143
154
element = fallback ;
144
155
}
0 commit comments