Next.js Discord

Discord Forum

Fetch on server & on client

Answered
Siamese posted this in #help-forum
Open in Discord
Avatar
SiameseOP
I'm using axios to do fetch calls either on server or on client.
Currently I'm experiencing the issue when I change the query params on the page and my server & client components do the same call.
For the time beeing I see the two soluions:
1) use unstable_cache to cache the result and prevent calls
2) use calls only on client (but I want the data to be in html after page loads (ssr), so this is not ideal)

Are there any other options to fix this?
Answered by B33fb0n3
@Siamese axios is dead. You can read more about it here: https://www.adios-axios.com/
You can still use it, but the default fetch function is so powerful now. So I recommend you switching on how to make a request from axios to fetch. Then you are good to go 🙂
View full answer

3 Replies

Avatar
B33fb0n3
@Siamese axios is dead. You can read more about it here: https://www.adios-axios.com/
You can still use it, but the default fetch function is so powerful now. So I recommend you switching on how to make a request from axios to fetch. Then you are good to go 🙂
Answer
Avatar
SiameseOP
Cool article, I'll lead this to my team, hope we can migrate.
Btw, by this you saying, to just utilize the default nextjs caching and don't worry about doubled requests?
Avatar
B33fb0n3
nextjs have multiple caching mechanisms. So you should care about fetching and you should check if everything is fine, but you should also handle the caching. Else you can get stale data. You can read more about caching und revalidation here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating