From 12e260dab320172a576b9dfffe6a36d09267f120 Mon Sep 17 00:00:00 2001 From: Daniel Fry Date: Tue, 20 Jun 2023 19:38:30 +0100 Subject: [PATCH] fix ErrorBoundary fallbackUI prop type definition (#95) * fix: fix ErrorBoundary fallbackUI prop * update type using ComponentType and use PropTypes.elementType for runtime type * use ComponentType import --------- Co-authored-by: Daniel Fry --- index.d.ts | 4 ++-- src/error-boundary.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2517ae2..692e721 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -import { Component, Context as ReactContext, ErrorInfo, ReactNode } from 'react'; +import { Component, Context as ReactContext, ErrorInfo, ReactNode, ComponentType } from 'react'; import Rollbar, { Callback, Configuration } from 'rollbar'; export const LEVEL_DEBUG = 'debug'; @@ -16,7 +16,7 @@ export type LEVEL = type Extra = Record; export interface ErrorBoundaryProps { children: ReactNode; - fallbackUI?: ReactNode; + fallbackUI?: ComponentType<{ error: Error | null, resetError: () => void }>; errorMessage?: string | (() => string); extra?: | Extra diff --git a/src/error-boundary.js b/src/error-boundary.js index 5408266..4527afe 100644 --- a/src/error-boundary.js +++ b/src/error-boundary.js @@ -11,7 +11,7 @@ export class ErrorBoundary extends Component { static contextType = Context; static propTypes = { - fallbackUI: PropTypes.func, + fallbackUI: PropTypes.elementType, errorMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), extra: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), level: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),