Skip to content

SWR

Data fetching with stale-while-revalidate semantics and a small API surface.

UnverifiedActive

Unverified

Compatibility has not been verified yet in the PreactHub catalog.

Packageswr

Facts at a glance
Preact compatibility
Unverified
Tested Preact versions
Not documented
TypeScript
Native TypeScript
SSR
SSR supported
Maintenance
Active
License
MIT
Last verified
Not yet verified
Terminal
npm install swr
Preact example
import useSWR from "swr"; const fetcher = (url: string) => fetch(url).then((res) => res.json()); export function User() {  const { data } = useSWR("/api/user", fetcher);  return <pre>{JSON.stringify(data, null, 2)}</pre>;}

Introduction

SWR stays appealing when you want data fetching with a smaller mental model than larger query frameworks.

Preact configuration

Typically used via `preact/compat` when integrated into Preact applications.

SSR notes

SSR behavior should be tested in the exact renderer and hydration strategy you use.

Islands notes

Useful for isolated widgets that fetch server state after hydration.

Alternatives