Next.js Discord

Discord Forum

Handle Next.js requests for client and server using fetch api

Unanswered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
How do you guys handle a single http client for both client and server requests using the fetch api?
I'd like to follow the best practices

10 Replies

Avatar
I am not sure wdym by "http client". But I'd keep the usage of "fetch" to minimum in the client side.

You want data? use server components
You want form submissions/button click? use server action
You want pagination, and search? use query params

If you want to use fetch in client side, just use the regular fetch, same as server side
Avatar
American Chinchilla
You can also use react query
Which is the standard in react
And next
Avatar
yeah, if you heavily depend on frontend fetching you should prolly use react query
Avatar
@American Chinchilla You can also use react query
Avatar
American black bearOP
but can I use react query on server side?
Avatar
American Chinchilla
You can check their docs
They explain how to cache server request into react query client side