Handle Next.js requests for client and server using fetch api
Unanswered
American black bear posted this in #help-forum
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
I'd like to follow the best practices
10 Replies
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
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 sideAmerican Chinchilla
You can also use react query
Which is the standard in react
And next
yeah, if you heavily depend on frontend fetching you should prolly use react query
@American Chinchilla You can also use react query
American black bearOP
but can I use react query on server side?
handle requests using axios fetch or whatever for both server and clide side
American Chinchilla
You can check their docs
They explain how to cache server request into react query client side