Still new to Next.js.
The web application will instead have a REST API for the actual backend stuff,
According to the moderator, if I will fetch via REST API, it is better to use stuff like TanStack query instead of server actions.
This weekend I went over the docs of TanStackQuery.
Which is the preferred way or the recommended way for Next.js + TanStack Query in this case?
Prefetching (https://tanstack.com/query/latest/docs/framework/react/examples/nextjs-app-prefetching) or streaming (https://tanstack.com/query/latest/docs/framework/react/examples/nextjs-suspense-streaming) ?
#TanStack Query and Next.js with REST API (data fetching preference)
10 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
TanStack Query and Next.js with REST API (data fetching preference)
yea, server actions are made for data mutations on the server (not for fetching data). Either directly fetch in your server component and pass the data down to your components or use a clientside fetching library like SWR or React Query like you mentioned
If I will use React Query, is there a community preferred way of data fetching or it will just depends on my own?
Additional question, if I will use React Query, is it okay to use axios or should I use fetch?
Based from what I heard, next.js enhanced the default fetch and it is better to use it when using next.js
yea, fetch in server components and pass to your component (no RQ needed). Else just useQuery from RQ inside client components
axios is dead. Read about it here: https://www.adios-axios.com/
Either use only fetch for the advantages you mentioned or if you need more use ky
Compelling reasons to replace Axios with the native Fetch API
I see, I didn't know.
Thank you very much!
✅ Success!
This question has been marked as answered! If you have any other questions, feel free to create another post
Jump to answer
[Click here](#1335550457984319548 message)