Skip to content

Commit 54a2838

Browse files
committed
Support null fallback prop
1 parent 23a4d77 commit 54a2838

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-error-boundary",
3-
"version": "4.0.11",
3+
"version": "4.0.12",
44
"description": "Simple reusable React error boundary component",
55
"author": "Brian Vaughn <[email protected]>",
66
"license": "MIT",

src/ErrorBoundary.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ describe("ErrorBoundary", () => {
151151
render({ resetKeys: [2] });
152152
expect(container.textContent).toBe("Content");
153153
});
154+
155+
it("should render a null fallback if specified", () => {
156+
shouldThrow = true;
157+
act(() => {
158+
root.render(
159+
<ErrorBoundary fallback={null}>
160+
<MaybeThrows>Content</MaybeThrows>
161+
</ErrorBoundary>
162+
);
163+
});
164+
expect(container.textContent).toBe("");
165+
});
154166
});
155167

156168
describe('"FallbackComponent"', () => {

src/ErrorBoundary.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export class ErrorBoundary extends Component<
9090
resetErrorBoundary: this.resetErrorBoundary,
9191
};
9292

93-
if (isValidElement(fallback)) {
94-
childToRender = fallback;
95-
} else if (typeof fallbackRender === "function") {
93+
if (typeof fallbackRender === "function") {
9694
childToRender = fallbackRender(props);
9795
} else if (FallbackComponent) {
9896
childToRender = createElement(FallbackComponent, props);
97+
} else if (fallback === null || isValidElement(fallback)) {
98+
childToRender = fallback;
9999
} else {
100100
if (isDevelopment) {
101101
console.error(

0 commit comments

Comments
 (0)