(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps)
| 8 | import type { ErrorBoundaryProps } from "../types"; |
| 9 | |
| 10 | export function withErrorBoundary< |
| 11 | Type extends ComponentClass<unknown>, |
| 12 | Props extends object, |
| 13 | >(Component: ComponentType<Props>, errorBoundaryProps: ErrorBoundaryProps) { |
| 14 | const Wrapped = forwardRef<InstanceType<Type>, Props>((props, ref) => |
| 15 | createElement( |
| 16 | ErrorBoundary, |
| 17 | errorBoundaryProps, |
| 18 | createElement(Component, { ...props, ref } as Props), |
| 19 | ), |
| 20 | ); |
| 21 | |
| 22 | // Format for display in DevTools |
| 23 | const name = Component.displayName || Component.name || "Unknown"; |
| 24 | Wrapped.displayName = `withErrorBoundary(${name})`; |
| 25 | |
| 26 | return Wrapped; |
| 27 | } |
no outgoing calls
searching dependent graphs…