Next.js Discord

Discord Forum

Pass data from server component to the client component

Answered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
I have a form in React Server Component and i want add some interactivity (update picture on page, depending on form data).
Is there any way to add some client code into server component ?
Answered by Stoyan Paskalev
Hi @Chinese Alligator , you can nest a client component inside a server one. The client component will hold the form logic and the updating can be done via server actions. Take a look at this --> https://nextjs.org/docs/app/api-reference/functions/server-actions
View full answer

4 Replies

use client component
you can add specific components to your server component, to make specific parts of your page interactive (clientside)
Hi @Chinese Alligator , you can nest a client component inside a server one. The client component will hold the form logic and the updating can be done via server actions. Take a look at this --> https://nextjs.org/docs/app/api-reference/functions/server-actions
Answer