( WrappedComponent: React.ComponentType<P>, errorBoundaryOptions: ErrorBoundaryProps, )
| 219 | |
| 220 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 221 | function withErrorBoundary<P extends Record<string, any>>( |
| 222 | WrappedComponent: React.ComponentType<P>, |
| 223 | errorBoundaryOptions: ErrorBoundaryProps, |
| 224 | ): React.FC<P> { |
| 225 | const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT; |
| 226 | |
| 227 | const Wrapped = React.memo((props: P) => ( |
| 228 | <ErrorBoundary {...errorBoundaryOptions}> |
| 229 | <WrappedComponent {...props} /> |
| 230 | </ErrorBoundary> |
| 231 | )) as unknown as React.FC<P>; |
| 232 | |
| 233 | Wrapped.displayName = `errorBoundary(${componentDisplayName})`; |
| 234 | |
| 235 | // Copy over static methods from Wrapped component to Profiler HOC |
| 236 | // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over |
| 237 | hoistNonReactStatics(Wrapped, WrappedComponent); |
| 238 | return Wrapped; |
| 239 | } |
| 240 | |
| 241 | export { ErrorBoundary, withErrorBoundary }; |
no test coverage detected