Skip to content
TelegramWhatsApp

Dictionary

SWR

SWR is a React hooks library for data fetching that implements the stale-while-revalidate caching strategy. The name comes from the HTTP Cache-Control directive: when data is requested, SWR immediately returns cached data if available, then sends a background fetch to revalidate and update with fresh data. This ensures the UI always shows something quickly while keeping data current.

The library handles common data fetching concerns automatically: request deduplication prevents redundant API calls when multiple components need the same data, focus revalidation refreshes data when users return to the browser tab, and interval polling keeps dashboards current. Error retry, pagination helpers, and optimistic UI updates are built in. For React developers, SWR simplifies server state management significantly compared to manual useEffect-based fetching, reducing boilerplate while providing a more robust data layer.