File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from "react"
2
+
3
+ import {
4
+ ErrorBoundary ,
5
+ ErrorBoundaryProps ,
6
+ OnDidCatchCallback ,
7
+ } from "./ErrorBoundary"
8
+
9
+ /**
10
+ * createErrorBoundary
11
+ * Accepts a onDidCatch callback.
12
+ * Creates a UseErrorBoundaryWrapper HOC, to keep the onDidCatch callback while
13
+ * still providing the ability to pass props to the ErrorBoundary
14
+ */
15
+
16
+ export type UseErrorBoundaryWrapper = (
17
+ props : Omit < ErrorBoundaryProps , "onDidCatch" >
18
+ ) => React . ReactElement
19
+
20
+ export function createErrorBoundary (
21
+ onDidCatch : OnDidCatchCallback
22
+ ) : UseErrorBoundaryWrapper {
23
+ // Return function component that wraps ErrorBoundary and passes props to it
24
+ return function UseErrorBoundaryWrapper ( props ) {
25
+ // Return ErrorBoundary with original onDidCatch and the current props
26
+ return React . createElement < ErrorBoundaryProps > ( ErrorBoundary , {
27
+ onDidCatch,
28
+ children : props . children ,
29
+ render : props . render ,
30
+ renderError : props . renderError ,
31
+ } )
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments