How to pass data of the client component to server component
Answered
JChicano posted this in #help-forum
JChicanoOP
I know that if you want to use a server component inside a client component, you must wrap it, but how i suppose to pass the data, if i have it in States in the client component?
Answered by joulev
you cant pass data from client components to server components in conventional means. you have to do it by interacting with the URL itself, for example by adding a search query
19 Replies
@JChicano I know that if you want to use a server component inside a client component, you must wrap it, but how i suppose to pass the data, if i have it in States in the client component?
you cant pass data from client components to server components in conventional means. you have to do it by interacting with the URL itself, for example by adding a search query
Answer
JChicanoOP
and if you want to pass sensitive data?
or for example if i want to do a sign up page, my form is a client component and i have to pass the data throw URL to have it in the server component and save it to the BBDD?
what is BBDD?
JChicanoOP
database*
@JChicano and if you want to pass sensitive data?
well, you can save it in the database
essentially, this is a restriction that you must abide by: server components only know the data present in the http request, which includes the URL and the http headers (including cookies). server components cannot know anything else, such as client-side states
i think is a better way, If I want to pass a lot of information from the client components to the server components
right?
yes cookies is also a valid way to pass data, yes
though if you want to hide it from the user, then cookies won't hide anything. users can always check the cookies content
JChicanoOP
and what do you recomend to do a sign up and login page?
@JChicano and what do you recomend to do a sign up and login page?
form => use server actions to handle the submission
JChicanoOP
oh, so i dont need a client component to handle the page in this case?
you can use a client component or a server component to make the form, no issues with either
JChicanoOP
ok, ty for the help mate 😄
Brown bear
Not sure if im allowed to ask a question on a already solved question. But I have a page (server comp) and a client component within it that has a form which uses some client validation. When a user submitts that form. Another server component on the same page needs that data.
What's the best solution then?
Client form > Submit data > Perform query to database > Server component needs the returned dataWhat's the best solution then?