[Solved] Error: Functions are not valid as a child of Client Components. #362
ADTC
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I copied this example (Add a dismiss button to all toasts using ToastBar) from the docs. However, upon page reload, I encountered this error:
Cause: I was constructing the
<Toaster>
and(t) => <ToastBar toast={t}>
inside an RSC (React Server Component).Reason: Even if
<Toaster>
itself is a client component, the rules of RSC state that children of a client component can be server components. The function is treated as a server component, which causes the error because functions cannot be streamed from the server to the client as children of client components.Solution: Move everything (
<Toaster>
and(t) => <ToastBar toast={t}>
) into a separate client component and then use the client component inside the parent RSC.Client Component
MyToaster.tsx/jsx
:RSC (React Server Component):
Beta Was this translation helpful? Give feedback.
All reactions