Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Query | 34,842 | a day ago | 43 | mit | TypeScript | |||||
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. | ||||||||||
Swr | 26,885 | 13 | 451 | a day ago | 124 | September 12, 2022 | 93 | mit | TypeScript | |
React Hooks for Data Fetching | ||||||||||
React Refetch | 3,436 | 157 | 22 | a month ago | 82 | January 20, 2020 | 50 | other | JavaScript | |
A simple, declarative, and composable way to fetch data for React components | ||||||||||
Use Http | 2,277 | 5 | 29 | 14 days ago | 101 | September 12, 2022 | 85 | mit | TypeScript | |
🐶 React hook for making isomorphic http requests | ||||||||||
React Async | 2,099 | 400 | 56 | 7 months ago | 90 | March 27, 2020 | 60 | isc | JavaScript | |
🍾 Flexible promise-based React data loader | ||||||||||
Rest Hooks | 1,794 | 3 days ago | 10 | apache-2.0 | TypeScript | |||||
Normalized state management for async data. Safe. Fast. Reusable. | ||||||||||
Cross Fetch | 1,545 | 14,308 | 1,942 | 12 hours ago | 40 | April 10, 2022 | 14 | mit | JavaScript | |
Universal WHATWG Fetch API for Node, Browsers and React Native. | ||||||||||
Alova | 1,156 | 2 days ago | 8 | mit | TypeScript | |||||
Request strategy library for MVVM libraries such as Vue.js, React.js and Svelte.js | ||||||||||
React Async Hook | 1,130 | 22 | 25 | 3 months ago | 26 | September 24, 2021 | 28 | TypeScript | ||
React hook to handle any async operation in React components, and prevent race conditions | ||||||||||
Redux Query | 1,103 | 12 | 7 | 3 days ago | 70 | June 30, 2022 | 2 | other | JavaScript | |
A library for managing network state in Redux |
SWR is a React Hooks library for data fetching.
The name SWR is derived from stale-while-revalidate
, a cache invalidation strategy popularized by HTTP RFC 5861.
SWR first returns the data from cache (stale), then sends the request (revalidate), and finally comes with the up-to-date data again.
With just one hook, you can significantly simplify the data fetching logic in your project. And it also covered in all aspects of speed, correctness, and stability to help you build better experiences:
...and a lot more.
With SWR, components will get a stream of data updates constantly and automatically. Thus, the UI will be always fast and reactive.
View full documentation and examples on swr.vercel.app.
import useSWR from 'swr'
function Profile() {
const { data, error } = useSWR('/api/user', fetcher)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data.name}!</div>
}
In this example, the React Hook useSWR
accepts a key
and a fetcher
function.
The key
is a unique identifier of the request, normally the URL of the API. And the fetcher
accepts
key
as its parameter and returns the data asynchronously.
useSWR
also returns 2 values: data
and error
. When the request (fetcher) is not yet finished,
data
will be undefined
. And when we get a response, it sets data
and error
based on the result
of fetcher
and rerenders the component.
Note that fetcher
can be any asynchronous function, you can use your favourite data-fetching
library to handle that part.
View full documentation and examples on swr.vercel.app.
This library is created by the team behind Next.js, with contributions from our community:
Thanks to Ryan Chen for providing the awesome swr
npm package name!
The MIT License.