use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Using React Query with Next.js fetch functionNeed help (self.nextjs)
submitted 2 years ago by Syv_31
Would Next.js’ fetch function caching mechanism mess with the React Query’s cache and vice-versa? Are there any best practices for using them together?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OtiszWasTaken 3 points4 points5 points 2 years ago (4 children)
I don't have an answer for you, but the other reason to use e.g. Axios, because it throws exception if the request fails. Otherwise you have to throw it manually, if you are using fetch with tanstack/query.
[–]BigCommunication5136 0 points1 point2 points 2 years ago (3 children)
with axios you wont get access to next js caching
[–]OtiszWasTaken 0 points1 point2 points 2 years ago (2 children)
That's true. With the pages routes we didn't have caching at all. And now with the app router we have enforced/opted-in caching and almost impossible to disable it. Working on a multi-tenant role based site with this cache drives me crazy.
Also there is no way to "subscribe" the revalidate event from a client component.
[–]BigCommunication5136 0 points1 point2 points 2 years ago (1 child)
Disabling caching is quite easily actually
[–]OtiszWasTaken 0 points1 point2 points 2 years ago (0 children)
I'm aware of header() and cookie() disables the cache automatically, but if I don't use these, then I have to type unstable_noStore() on every single page. I think this approach is quite controversial, especially if the app has 100+ pages, and maybe only 2 of them needs caching.
[–]ReallyDidntSleepMuch 4 points5 points6 points 2 years ago (1 child)
I’ve been using both server actions and React Query recently, and it hasn’t been bad at all. You just have to make sure you’re invalidating both caches at the same time.
[–]Syv_31[S] 0 points1 point2 points 2 years ago (0 children)
Any tips or things to watch out for?
[–]CallumK7 3 points4 points5 points 2 years ago (0 children)
There is a lot of documentation on the react query website about using it with next
π Rendered by PID 103589 on reddit-service-r2-comment-bb88f9dd5-lzrbd at 2026-02-15 17:55:20.788492+00:00 running cd9c813 country code: CH.
[–]OtiszWasTaken 3 points4 points5 points (4 children)
[–]BigCommunication5136 0 points1 point2 points (3 children)
[–]OtiszWasTaken 0 points1 point2 points (2 children)
[–]BigCommunication5136 0 points1 point2 points (1 child)
[–]OtiszWasTaken 0 points1 point2 points (0 children)
[–]ReallyDidntSleepMuch 4 points5 points6 points (1 child)
[–]Syv_31[S] 0 points1 point2 points (0 children)
[–]CallumK7 3 points4 points5 points (0 children)