@@ -4,21 +4,31 @@ import * as React from 'react';
4
4
5
5
export const UNKNOWN_COMPONENT = 'unknown' ;
6
6
7
+ export type FallbackRender = ( fallback : {
8
+ error : Error | null ;
9
+ componentStack : string | null ;
10
+ resetError ( ) : void ;
11
+ } ) => React . ReactNode ;
12
+
7
13
export type ErrorBoundaryProps = {
8
14
showDialog ?: boolean ;
9
15
dialogOptions ?: Sentry . ReportDialogOptions ;
10
- fallback ?: React . ReactNode ;
11
- fallbackRender ?( fallback : {
12
- error : Error | null ;
13
- componentStack : string | null ;
14
- resetError ( ) : void ;
15
- } ) : React . ReactNode ;
16
+ // tslint:disable-next-line: no-null-undefined-union
17
+ fallback ?: React . ReactNode | FallbackRender ;
16
18
onError ?( error : Error , componentStack : string ) : void ;
17
19
onMount ?( ) : void ;
18
20
onReset ?( error : Error | null , componentStack : string | null ) : void ;
19
21
onUnmount ?( error : Error | null , componentStack : string | null ) : void ;
20
22
} ;
21
23
24
+ /*
25
+ fallbackRender?(fallback: {
26
+ error: Error | null;
27
+ componentStack: string | null;
28
+ resetError(): void;
29
+ }): React.ReactNode;
30
+ */
31
+
22
32
type ErrorBoundaryState = {
23
33
componentStack : string | null ;
24
34
error : Error | null ;
@@ -71,16 +81,16 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
71
81
} ;
72
82
73
83
public render ( ) : React . ReactNode {
74
- const { fallback, fallbackRender } = this . props ;
84
+ const { fallback } = this . props ;
75
85
const { error, componentStack } = this . state ;
76
86
77
87
if ( error ) {
78
- if ( typeof fallbackRender === 'function' ) {
79
- return fallbackRender ( { error, componentStack, resetError : this . resetErrorBoundary } ) ;
80
- }
81
88
if ( React . isValidElement ( fallback ) ) {
82
89
return fallback ;
83
90
}
91
+ if ( typeof fallback === 'function' ) {
92
+ return fallback ( { error, componentStack, resetError : this . resetErrorBoundary } ) as FallbackRender ;
93
+ }
84
94
85
95
// Fail gracefully if no fallback provided
86
96
return null ;
0 commit comments