#App router react query

1 messages · Page 1 of 1 (latest)

ionic gorge
#

Is there a benefit to using tanstack request query client in an app where all data is fetched on the server at build time built with the nextjs app router, or is it ok to use fetch

heavy pewterBOT
#

Hi @ionic gorge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Next.js allows you to choose your data fetching strategy based on your needs. You can decide to fetch data at build time, at request time on the server, or on the client. If all your data is fetched on the server at build time, you can use fetch to get your data from your CMS and render your blog posts, which can then be efficiently cached on a CDN (source (https://nextjs.org/docs/app/building-your-application/upgrading/from-create-react-app#choose-the-data-fetching-strategy)).

However, if you decide to implement client-side rendering, you can use a data fetching library like TanStack Query. This is recommended when you don't need to pre-render your data, or when the content of your pages needs to update frequently. Client-side data fetching can be done at the page level or at the component level (source (https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side)).

It's important to note that using client-side data fetching can affect the performance of your application and the load speed of your pages. This is because the data fetching is done at the time of the component or pages mount, and the data is not cached (source (https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side)).

In conclusion, whether to use fetch or a data fetching library like TanStack Query depends on your specific needs and the data fetching strategy you choose.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: