data fetching and rendering
Unanswered
Boby posted this in #help-forum
BobyOP
I am trying to fetch data but not able to, and can somebody please also tell whether I am using the right paradigm to fetch the data and render it or nah?
Any help would be highly appreciated.
https://github.com/Boby900/yogurt
Any help would be highly appreciated.
https://github.com/Boby900/yogurt
19 Replies
you should directly fetch the data inside the server component instead of fetching data in api routes, and then fetching api route from the component.
oh, you are doing it on
onClick@averydelusionalperson oh, you are doing it on `onClick`
BobyOP
thanks for jumping in
if I am fetching the data using the
onClick so can I fetch it directly using the server component or the way I am doing it is right.if you can share some article or an examples of data fetching and rendering it, that would be great.
thanks for your help.
@Boby thanks for jumping in
Giant panda
you can directly fetch the data in server components btw why you want to fetch data with onClick event ?
@Giant panda you can directly fetch the data in server components btw why you want to fetch data with onClick event ?
BobyOP
thanks, more clear to me now
I had asked the chatgpt on how to fetch data in Next.js so it was using
onClick to fetch the data so I have just copy pasted thatbut I think I am better off directly fetching the data using the server component
Giant panda
that's not how you should fetch data in react/nextjs
you can either fetch data using useEffect for client side components or use server components
@Giant panda that's not how you should fetch data in react/nextjs
BobyOP
okay, thanks for the clarification
what about server actions can we use them with the event listener?
I am new to Next.js so I am just clearing my doubts
sorry for asking dumb questions
Giant panda
Yes
You can