Skip to content

Commit 8b2c6c5

Browse files
Re-throw original error if no fallback provided (#160)
In development environments, also log a console.error message. --------- Co-authored-by: Brian Vaughn <[email protected]>
1 parent 341f67d commit 8b2c6c5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ErrorBoundary.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isDevelopment } from "#is-development";
12
import { Component, createElement, ErrorInfo, isValidElement } from "react";
23
import { ErrorBoundaryContext } from "./ErrorBoundaryContext";
34
import { ErrorBoundaryProps, FallbackProps } from "./types";
@@ -88,9 +89,13 @@ export class ErrorBoundary extends Component<
8889
} else if (FallbackComponent) {
8990
childToRender = createElement(FallbackComponent, props);
9091
} else {
91-
throw new Error(
92-
"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop"
93-
);
92+
if (isDevelopment) {
93+
console.error(
94+
"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop"
95+
);
96+
}
97+
98+
throw error;
9499
}
95100
}
96101

0 commit comments

Comments
 (0)