npm i @hazae41/xswr
Read the docs ๐ โข Try it online ๐ โข Next.js CodeSandbox ๐ชฃ โข Comparison with other libs ๐
Philosophy ๐ง
xswr uses two new approaches compared to other data fetching libraries like swr or react-query:
- Encapsulating key+fetcher+params in a single abstraction called schema.
- Composing features with very simple hooks instead of having bloated configuration and unexpected behaviors.
Features ๐ฅ
Current features
- 100% TypeScript and ESM
- Composition-based hooks
- Very easy learning curve
- No dependency except React
- Not over-engineered (hello react-query)
- No unexpected behaviour (hello swr)
- Backend agnostic fetching (REST, GraphQL, WebSocket)
- Storage agnostic caching (new Map(), LocalStorage, IndexedDB)
- Automatic refetching
- Dependent and conditional queries
- Request deduplication, cooldown, timeout, and expiration
- Page-based and cursor-based pagination
- Exponential backoff retry
- SSR & ISR support
- Optimistic mutations
- Cancellable requests
- Automatic cancellation
- Automatic garbage collection
- Per-query persistent storage
- Out of the box IndexedDB and LocalStorage
- Out of the box store normalization
- Super natural React Suspense
Upcoming features
- Transport agnostic streaming (ethers.js, WebSockets, Socket.io)
- Bidirectional scrolling