@hrnec06/react_utils 1.11.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hrnec06/react_utils",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "React utilities",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -3,8 +3,10 @@ import useSignal, { Signal } from "../../../hooks/useSignal";
3
3
  import { ErrorBoundaryContext } from "./ErrorBoundaryContext";
4
4
  import React from "react";
5
5
 
6
+ type FallbackType = React.ReactNode | ((error: Error) => React.ReactNode);
7
+
6
8
  type ErrorBoundaryProps = ReactUtils.Props<{
7
- fallback: React.ReactNode,
9
+ fallback: FallbackType,
8
10
  children: React.ReactNode
9
11
  }>;
10
12
  export default function ErrorBoundary({
@@ -28,7 +30,7 @@ export default function ErrorBoundary({
28
30
  {children}
29
31
  </ErrorCatcher>
30
32
  ) : (
31
- fallback
33
+ <ErrorFallback error={error.value} fallback={fallback} />
32
34
  )
33
35
  }
34
36
  </ErrorBoundaryContext.Provider>
@@ -63,4 +65,18 @@ class ErrorCatcher extends React.Component<ErrorCatcherProps>
63
65
  {
64
66
  return this.props.children;
65
67
  }
68
+ }
69
+
70
+ type ErrorFallback = ReactUtils.Props<{
71
+ fallback: FallbackType,
72
+ error: Error
73
+ }>;
74
+ function ErrorFallback({ error, fallback }: ErrorFallback)
75
+ {
76
+ if (typeof fallback === "function")
77
+ {
78
+ return fallback(error);
79
+ }
80
+
81
+ return fallback;
66
82
  }