Skip to content

Commit e7966d5

Browse files
authored
Merge pull request #130 from eps1lon/rsc-directive
feat: Improve error message when used in React Server Components
2 parents 3893cab + 050aecb commit e7966d5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ yarn add react-error-boundary
1919
### `ErrorBoundary` component
2020
Wrap an `ErrorBoundary` around other React components to "catch" errors and render a fallback UI. The component supports several ways to render a fallback (shown below).
2121

22+
> **Note** `ErrorBoundary` is a _client_ component. You can only pass props to it that are serializeable or use it in files that have a `"use client";` directive.
23+
2224
#### `ErrorBoundary` with `fallback` prop
2325
The simplest way to render a default "something went wrong" type error message.
2426
```js
27+
"use client";
28+
2529
import { ErrorBoundary } from "react-error-boundary";
2630

2731
<ErrorBoundary fallback={<div>Something went wrong</div>}>
@@ -31,6 +35,8 @@ import { ErrorBoundary } from "react-error-boundary";
3135
#### `ErrorBoundary` with `fallbackRender` prop
3236
["Render prop"](https://react.dev/reference/react/Children#calling-a-render-prop-to-customize-rendering) function responsible for returning a fallback UI based on a thrown value.
3337
```js
38+
"use client";
39+
3440
import { ErrorBoundary } from "react-error-boundary";
3541

3642
function fallbackRender({ error, resetErrorBoundary }) {
@@ -56,6 +62,8 @@ function fallbackRender({ error, resetErrorBoundary }) {
5662
#### `ErrorBoundary` with `FallbackComponent` prop
5763
React component responsible for returning a fallback UI based on a thrown value.
5864
```js
65+
"use client";
66+
5967
import { ErrorBoundary } from "react-error-boundary";
6068

6169
function Fallback({ error, resetErrorBoundary }) {
@@ -82,6 +90,8 @@ function Fallback({ error, resetErrorBoundary }) {
8290
#### Logging errors with `onError`
8391

8492
```js
93+
"use client";
94+
8595
import { ErrorBoundary } from "react-error-boundary";
8696

8797
const logError = (error: Error, info: { componentStack: string }) => {
@@ -105,6 +115,8 @@ React only handles errors thrown during render or during component lifecycle met
105115
This hook can be used to pass those errors to the nearest error boundary:
106116

107117
```js
118+
"use client";
119+
108120
import { useErrorBoundary } from "react-error-boundary";
109121

110122
function Example() {
@@ -130,6 +142,8 @@ function Example() {
130142
A fallback component can use this hook to request the nearest error boundary retry the render that original failed.
131143

132144
```js
145+
"use client";
146+
133147
import { useErrorBoundary } from "react-error-boundary";
134148

135149
function ErrorFallback({ error }) {
@@ -149,6 +163,8 @@ function ErrorFallback({ error }) {
149163
This package can also be used as a [higher-order component](https://legacy.reactjs.org/docs/higher-order-components.html) that accepts all of the same props as above:
150164

151165
```js
166+
"use client";
167+
152168
import {withErrorBoundary} from 'react-error-boundary'
153169

154170
const ComponentWithErrorBoundary = withErrorBoundary(ExampleComponent, {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
export * from "./ErrorBoundary";
24
export * from "./ErrorBoundaryContext";
35
export * from "./useErrorBoundary";

0 commit comments

Comments
 (0)