https://github.com/danybeltran/swr-micro
A lightweight SWR implementation using atomic-state
https://github.com/danybeltran/swr-micro
axios data-dependency deduplication fetch https ssr suspense swr
Last synced: 5 months ago
JSON representation
A lightweight SWR implementation using atomic-state
- Host: GitHub
- URL: https://github.com/danybeltran/swr-micro
- Owner: danybeltran
- License: mit
- Created: 2023-02-13T13:30:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-15T08:11:43.000Z (about 2 years ago)
- Last Synced: 2024-10-06T09:44:00.200Z (9 months ago)
- Topics: axios, data-dependency, deduplication, fetch, https, ssr, suspense, swr
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/swr-micro
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### swr-micro
A lightweight SWR implementation using `atomic-state`
Example code
```tsx
import useSWR from 'swr-micro'const fetcher = (url, config) => fetch(url, config)
export default function Page() {
const [page, setPage] = useState(1)const { data, loading, error, revalidating } = useSWR('https://jsonplaceholder.typicode.com/todos/[id]', {
params: {
id: page
}
})if(loading) return
Loading
if(error) return
Error
return (
setPage(page - 1)}>{'<'}
{page}
setPage(page + 1)}>{'>'}
Refresh
{JSON.stringify(data, null, 2)}
)
}
```
> Note that `revalidating` will not be true during the first revalidation### Features:
- Pagination
- Request deduplication
- Data dependency
- Local mutation for optimistic UI
- Suspense
- Custom fetcher (e.g. `axios`, `fetch`)
- Search params
- Revalidate with interval
- Error-retry
- Retry on reconnect