From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Query caching & refetching

Query caching & refetching

Hello, and welcome! The aim of this session is to understand how React Query caches data and how it handles refetching to keep your app data fresh. Caching is a powerful feature that can make your applications feel incredibly fast and responsive by avoiding unnecessary network requests. We'll also explore how React Query ensures your data doesn't become stale. Let's start where we left in the previous session. Now I am adding a simple console.log inside our FetchCourses function. The sole purpose of this line is to give us a clear signal in the browser's developer console whenever this function is actually executed. This is our window into React Query's behavior. When you see FetchingCourses logged, you know a genuine network request is being made. When you navigate around the app and don't see this message, you'll know that React Query is serving the data from its cache. Okay, let's talk about one of the most important configuration options – stale time. I've just added stale time…

Contents