Skip to content

Commit

Permalink
Support null fallback prop
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Dec 15, 2023
1 parent 23a4d77 commit 54a2838
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-error-boundary",
"version": "4.0.11",
"version": "4.0.12",
"description": "Simple reusable React error boundary component",
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
"license": "MIT",
Expand Down
12 changes: 12 additions & 0 deletions src/ErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ describe("ErrorBoundary", () => {
render({ resetKeys: [2] });
expect(container.textContent).toBe("Content");
});

it("should render a null fallback if specified", () => {
shouldThrow = true;
act(() => {
root.render(
<ErrorBoundary fallback={null}>
<MaybeThrows>Content</MaybeThrows>
</ErrorBoundary>
);
});
expect(container.textContent).toBe("");
});
});

describe('"FallbackComponent"', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/ErrorBoundary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export class ErrorBoundary extends Component<
resetErrorBoundary: this.resetErrorBoundary,
};

if (isValidElement(fallback)) {
childToRender = fallback;
} else if (typeof fallbackRender === "function") {
if (typeof fallbackRender === "function") {
childToRender = fallbackRender(props);
} else if (FallbackComponent) {
childToRender = createElement(FallbackComponent, props);
} else if (fallback === null || isValidElement(fallback)) {
childToRender = fallback;
} else {
if (isDevelopment) {
console.error(
Expand Down

0 comments on commit 54a2838

Please sign in to comment.