Gathering detailed insights and metrics for swr
Gathering detailed insights and metrics for swr
Gathering detailed insights and metrics for swr
Gathering detailed insights and metrics for swr
npm install swr
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
30,622 Stars
881 Commits
1,220 Forks
217 Watching
16 Branches
244 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (99.22%)
JavaScript (0.77%)
Shell (0.02%)
Cumulative downloads
Total Downloads
Last day
-5.4%
449,286
Compared to previous day
Last week
11.8%
2,712,624
Compared to previous week
Last month
7.7%
10,598,785
Compared to previous month
Last year
62.6%
103,038,193
Compared to previous year
2
1
33
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.
1import useSWR from 'swr' 2 3function Profile() { 4 const { data, error, isLoading } = useSWR('/api/user', fetcher) 5 6 if (error) return <div>failed to load</div> 7 if (isLoading) return <div>loading...</div> 8 return <div>hello {data.name}!</div> 9}
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 3 values: data
, isLoading
and error
. When the request (fetcher) is not yet finished,
data
will be undefined
and isLoading
will be true
. When we get a response, it sets data
and error
based on the result
of fetcher
, isLoading
to false 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.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 20/30 approved changesets -- score normalized to 6
Reason
0 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 2
Reason
8 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More