Next.js Discord

Discord Forum

Data Fetching

Answered
~/.BeastieNate5 posted this in #help-forum
Open in Discord
I’ve been trying to figure this out for a while but I have a client component that needs to get access to data on a API. But I don’t want the code to execute on the client, I want it to be done on the server and then it gets received from the server. I don’t want to use server actions since it can only use post. What should I do?
Answered by ~/.BeastieNate5
I was thinking about using routes handlers
View full answer

12 Replies

I keep seeing "fetch the data in a RSC then pass it down to a client component"
the only problem is that I need the server component to be able to access data from the child client component. Depending on that value will determine what data it fetches
basically the client and server component would need to keep commuincating
Ah ok this makes sense
I was thinking about using routes handlers
Answer
would that also work?
cause to me it sounds like they are kinda doing the samething
@~/.BeastieNate5 I was thinking about using routes handlers
it works too, but in that case you are doing client-side data fetching which may or may not be what you want
i mean it should be fine for me. the route handler is executed on the server right? plus my api does not have any sensitive information
ah yes route handlers run on the server
ok perfect i have two ways to do this, thanks for the info