Next.js Discord

Discord Forum

fetch from server or client Component

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Avatar
Asian black bearOP
which one should I fetch from? if I want to fetch from my api router
Image

15 Replies

Avatar
if u have a route handler u fetch from clientside only
Avatar
Asian black bearOP
yeah why?
is it because it overloads server something like that?
Avatar
Asian black bearOP
btw I have to get cookies
Avatar
no because fetching your own route handler trough a ssr component will brake on production
and its not recommended
use this
u can use this anywhere on the server and that is part on the request context
Avatar
Asian black bearOP
well then I should use server for cookies and client for fetching?
Avatar
u can fetch from serverside
just make sure u dont fetch your own route handler
on the server
while on client u can do that
Avatar
Asian black bearOP
oh thank you bro!