Pass data from server component to the client component
Answered
Chinese Alligator posted this in #help-forum
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 ?
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
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
@Stoyan Paskalev Hi <@780818523546714123> , 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
Chinese AlligatorOP
thank you @Stoyan Paskalev this is solution