SWR is a React Hooks library for remote data fetching.
Some interesting features:
- When you re-focus a page or switch between tabs, SWR automatically revalidates data.
- SWR automatically revalidate the data from the origin as soon as data is rendered from the cache.
- SWR will make cached pages render much faster, then update the cache with the latest data.
- SWR will give you the option to automatically refetch data, which is helpful when data changes because of multiple devices, users, or tabs.
- SWR scales extremely well because it requires very little effort to write applications that automatically and eventually converge to the most recent remote data.
- SWR allows you to fetch data that depends on other data.
- You can also use SWR Hooks with React Suspense.
The name “SWR” is derived from stale-while-revalidate, a HTTP cache invalidation strategy popularized by RFC 5861.
SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.