All Projects → vercel → Swr

vercel / Swr

Licence: mit
React Hooks for data fetching

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Swr

swr-examples
SWR is a React Hook library for remote data fetching. Here are some simple examples.
Stars: ✭ 14 (-99.93%)
Mutual labels:  fetch, nextjs, swr
React Query
⚛️ Hooks for fetching, caching and updating asynchronous data in React
Stars: ✭ 24,427 (+20.05%)
Mutual labels:  fetch, hooks, stale-while-revalidate
use-async-resource
A custom React hook for simple data fetching with React Suspense
Stars: ✭ 92 (-99.55%)
Mutual labels:  fetch, data-fetching, suspense
static-template-nextjs
A Next.js based template of a blog built using the Collected Notes API
Stars: ✭ 19 (-99.91%)
Mutual labels:  nextjs, swr, vercel
mey
A react package that exports hooks for handling the request lifecycle.
Stars: ✭ 18 (-99.91%)
Mutual labels:  fetch, hooks, data-fetching
netease-music-app
网易云音乐移动端【React/Next/Vue】【Ant Design/Material UI】
Stars: ✭ 95 (-99.53%)
Mutual labels:  nextjs, swr
devdevdev
The next trendy apparel e-commerce store maybe?
Stars: ✭ 27 (-99.87%)
Mutual labels:  nextjs, zeit
use-mutation
🧬 Run side-effects safely in React
Stars: ✭ 81 (-99.6%)
Mutual labels:  hooks, swr
notion-nextjs-blog
A starter blog template powered by Next.js, Notion and Tailwind CSS.
Stars: ✭ 25 (-99.88%)
Mutual labels:  nextjs, vercel
wefootwear-store
next js footwear store e-commerce 🚀🚀🚀
Stars: ✭ 17 (-99.92%)
Mutual labels:  nextjs, vercel
expansion-pack
🔋 Useful stack expansion for ts-nextjs-tailwind-starter
Stars: ✭ 16 (-99.92%)
Mutual labels:  nextjs, swr
Personal-Site-Gourav.io
My personal site & blog made with NextJS, Typescript, MDX, Tailwind CSS. Deployed on Vercel : https://gourav.io
Stars: ✭ 64 (-99.69%)
Mutual labels:  nextjs, vercel
website
My portfolio 👋
Stars: ✭ 232 (-98.86%)
Mutual labels:  nextjs, vercel
react-movies-finder
React Movies finder is a React app to search movies and series using redux, redux-thunk, React Hooks, and Material UI
Stars: ✭ 27 (-99.87%)
Mutual labels:  hooks, nextjs
onlysetups
OnlyFans, but for pictures of desk setups.
Stars: ✭ 82 (-99.6%)
Mutual labels:  nextjs, vercel
yearn-comms
Collection of communication, announcements, tweets, newsletters, and other articles about Yearn and a hosted blog for all translation contributors.
Stars: ✭ 16 (-99.92%)
Mutual labels:  nextjs, vercel
next-use-contextual-routing
Generate contextual routing / modal routes paths for Next.js
Stars: ✭ 76 (-99.63%)
Mutual labels:  hook, nextjs
MouseInjectDetection
Simple method of checking whether or not mouse movement or buttons (<windows 10) are injected
Stars: ✭ 29 (-99.86%)
Mutual labels:  hooks, hook
React Fetch Hook
React hook for conveniently use Fetch API
Stars: ✭ 285 (-98.6%)
Mutual labels:  fetch, hooks
use-bus
React hook to subscribe and dispatch events accros React components
Stars: ✭ 51 (-99.75%)
Mutual labels:  hooks, hook

SWR


Introduction

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:

  • Fast, lightweight and reusable data fetching
  • Transport and protocol agnostic
  • Built-in cache and request deduplication
  • Real-time experience
  • Revalidation on focus
  • Revalidation on network recovery
  • Polling
  • Pagination and scroll position recovery
  • SSR and SSG
  • Local mutation (Optimistic UI)
  • Built-in smart error retry
  • TypeScript
  • React Suspense
  • React Native

...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.


Quick Start

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.


Authors

This library is created by the team behind Next.js, with contributions from our community:

Contributors

Thanks to Ryan Chen for providing the awesome swr npm package name!


License

The MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].