how to pass server data to client component
Unanswered
American black bear posted this in #help-forum
American black bearOP
im trying to create a client side form and i need some information from the database to be shown in the ux. for instance, the user has to choose between some options and these options are fetched from a database. how would i create this?
20 Replies
American black bearOP
bump
Serengeti
You want to make the page.tsx (so the root page of the route) to be a server component, fetch the relevant data there from the database and then make the form a client component to which you pass the data as props
@Serengeti You want to make the page.tsx (so the root page of the route) to be a server component, fetch the relevant data there from the database and then make the form a client component to which you pass the data as props
American black bearOP
could you make a small example please, im new to nextjs i dont understand it too clearly please
Serengeti
If you haven’t worked with it yet I highly recommend you take the next js tutorial, they have an official free one and it will teach you all of this and more
@Serengeti If you haven’t worked with it yet I highly recommend you take the next js tutorial, they have an official free one and it will teach you all of this and more
American black bearOP
do you have a link for it? would much appreciate it thank you very much
Argente Brun
https://nextjs.org/learn/dashboard-app/getting-started
@American black bear is the offical free course of NextJS
@American black bear is the offical free course of NextJS
@Argente Brun https://nextjs.org/learn/dashboard-app/getting-started
<@489852928341835776> is the offical free course of NextJS
American black bearOP
i was talking about the form issue im having but thanks anyways
Serengeti
@American black bear that tutorial has exactly what you're looking for
The question you asked, the answer you would know by learning the basics of server components. That's why I suggested you take the course to learn it
@American black bear im trying to create a client side form and i need some information from the database to be shown in the ux. for instance, the user has to choose between some options and these options are fetched from a database. how would i create this?
American black bear
you get data in a server component
and have a seperate form component as client
and pass data from server -> client
I would share sample code
but I don't have code open RN
@American black bear I would share sample code
American black bearOP
that would help a lot if possible, i can wait. thank you very much
Serengeti
I still think you would benefit much more from just going through the course, him showing you a simple example still won't properly teach you how to use Next.js.
but since you're so insistant, here's your example
@Serengeti Click to see attachment
American black bear
Yeah, like this
@Serengeti I still think you would benefit much more from just going through the course, him showing you a simple example still won't properly teach you how to use Next.js.
American black bearOP
i know but i really need to fix this issue fast, i will go through the course tho thank you