From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

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

SWR (Stale-While-Revalidate) example

SWR (Stale-While-Revalidate) example

Welcome back, in this video we are going to learn about another server state management library that is SWR, State While Revalidate. This one is developed by Vercel, the very famous Next.js team. The philosophy behind this SWR library is that data fetching should be as simple as use state. So when you are not looking to apply any complex concepts and you are just looking to get faster development with a server state management library, then you can use SWR. The features this library offers are, it has auto-revalidation. It is going to revalidate your data. If it has become stale, then it will revalidate and fetch the latest data. It also has caching support but is limited. Unlike the 10 stack query, the focus of this library is to refetch when the tab regains focus. This is an example that for example, you have a page that has been loaded for quite a while and as soon as you get focus on that tab or that page, it is going to check if there is a data update, it will revalidate and sync…

Contents