An open API service indexing awesome lists of open source software.

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

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