Skip to content

Commit db424c4

Browse files
authored
Update ErrorBoundary.ts
console.error wrapped with is-development conditional
1 parent 7489466 commit db424c4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/ErrorBoundary.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Component, createElement, ErrorInfo, isValidElement } from "react";
1+
import { isDevelopment } from "#is-development";
2+
import {
3+
Component,
4+
createElement,
5+
ErrorInfo,
6+
isValidElement,
7+
PropsWithChildren,
8+
PropsWithRef,
9+
ReactElement,
10+
} from "react";
211
import { ErrorBoundaryContext } from "./ErrorBoundaryContext";
312
import { ErrorBoundaryProps, FallbackProps } from "./types";
413

@@ -10,7 +19,7 @@ const initialState: ErrorBoundaryState = {
1019
};
1120

1221
export class ErrorBoundary extends Component<
13-
ErrorBoundaryProps,
22+
PropsWithRef<PropsWithChildren<ErrorBoundaryProps>>,
1423
ErrorBoundaryState
1524
> {
1625
constructor(props: ErrorBoundaryProps) {
@@ -88,9 +97,12 @@ export class ErrorBoundary extends Component<
8897
} else if (FallbackComponent) {
8998
childToRender = createElement(FallbackComponent, props);
9099
} else {
91-
console.error(
92-
"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop"
93-
);
100+
if (isDevelopment) {
101+
console.error(
102+
"react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop"
103+
);
104+
}
105+
94106
throw error;
95107
}
96108
}

0 commit comments

Comments
 (0)