Skip to content

Commit 0ec2bfa

Browse files
committed
Readme tweaks
1 parent cc27469 commit 0ec2bfa

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22

33
Sample reusable React error boundary component for React 16+
44

5+
The simplest way to use a boundary is to wrap it around any component that may throw an error.
6+
This will handle errors thrown by that component's descendents also.
7+
58
```jsx
69
import ErrorBoundary from 'react-error-boundary';
710

8-
// The simplest way to use a boundary;
9-
// Wrap around any component that may throw an error:
1011
<ErrorBoundary>
1112
<ComponentThatMayError />
1213
</ErrorBoundary>
14+
```
15+
16+
You can also react to errors (eg for logging) by providing an `onError` callback:
17+
18+
```jsx
19+
import ErrorBoundary from 'react-error-boundary';
20+
21+
const myErrorHandler = (error: Error, componentStack: string) => {
22+
// ...
23+
};
1324

14-
// You can also react to errors (eg for logging):
15-
const myErrorHandler = (error, componentStack) => {/* ... */}
1625
<ErrorBoundary onError={myErrorHandler}>
1726
<ComponentThatMayError />
1827
</ErrorBoundary>
28+
```
29+
30+
You can also customize the fallback appearance:
31+
32+
```jsx
33+
const MyFallbackComponent = ({ componentStack, error }) => (
34+
<div/>
35+
)
1936

20-
// You can also customize the fallback appearance:
21-
const MyFallbackComponent = ({ componentStack, error }) => (/* ... */)
2237
<ErrorBoundary FallbackComponent={MyFallbackComponent}>
2338
<ComponentThatMayError />
2439
</ErrorBoundary>

0 commit comments

Comments
 (0)