You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/rsc/use-client.md
+93-1Lines changed: 93 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -376,4 +376,96 @@ These libraries may rely on component Hooks or client APIs. Third-party componen
376
376
377
377
If these libraries have been updated to be compatible with React Server Components, then they will already include `'use client'` markers of their own, allowing you to use them directly from your Server Components. If a library hasn't been updated, or if a component needs props like event handlers that can only be specified on the client, you may need to add your own Client Component file in between the third-party Client Component and your Server Component where you'd like to use it.
378
378
379
-
[TODO]: <>(Troubleshooting - need use-cases)
379
+
## Troubleshooting {/*troubleshooting*/}
380
+
381
+
### "Functions cannot be passed directly to Client Components" error {/*functions-cannot-be-passed-directly*/}
382
+
383
+
This error occurs when you try to pass a function from a Server Component to a Client Component.
384
+
385
+
```js
386
+
// Server Component
387
+
importClientButtonfrom'./ClientButton';
388
+
389
+
exportdefaultfunctionPage() {
390
+
functionhandleClick() {
391
+
console.log('clicked');
392
+
}
393
+
// This will error!
394
+
return<ClientButton onClick={handleClick} />;
395
+
}
396
+
```
397
+
398
+
Functions are not serializable, so they cannot be passed from server to client. To fix this, either move the function to the Client Component, or use a [Server Function](/reference/rsc/server-functions) with `'use server'`.
399
+
400
+
```js
401
+
// Solution 1: Move the handler to the Client Component
### Third-party library doesn't work in Server Components {/*third-party-library-server-component*/}
449
+
450
+
Many third-party libraries were written before Server Components existed and may use client-only features. If you get an error when importing a library in a Server Component, create a wrapper Client Component:
0 commit comments