https://github.com/sergiodxa/swr-sync-storage
Synchronize SWR cache with localStorage or sessionStorage to get offline cache
https://github.com/sergiodxa/swr-sync-storage
localstorage sessionstorage swr swr-sync-storage web-storage
Last synced: about 1 year ago
JSON representation
Synchronize SWR cache with localStorage or sessionStorage to get offline cache
- Host: GitHub
- URL: https://github.com/sergiodxa/swr-sync-storage
- Owner: sergiodxa
- License: mit
- Created: 2020-03-01T06:38:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-25T10:01:14.000Z (over 3 years ago)
- Last Synced: 2025-03-27T20:12:01.411Z (about 1 year ago)
- Topics: localstorage, sessionstorage, swr, swr-sync-storage, web-storage
- Language: TypeScript
- Size: 1.06 MB
- Stars: 110
- Watchers: 2
- Forks: 4
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# swr-sync-storage


[](https://codeclimate.com/github/sergiodxa/swr-sync-storage/maintainability)
[](https://codeclimate.com/github/sergiodxa/swr-sync-storage/test_coverage)
Synchronize SWR cache with localStorage or sessionStorage to get offline cache.
## Usage
Install it
```sh
$ yarn add swr-sync-storage
```
> Note: You will need to provide SWR v0.2.0-beta.0 or greater
```ts
import { syncWithStorage } from "swr-sync-storage";
syncWithStorage("local");
syncWithStorage("session");
```
You can also import to already bound versions of local or session storage.
```ts
import { syncWithLocalStorage } from "swr-sync-storage";
syncWithLocalStorage();
```
```ts
import { syncWithSessionStorage } from "swr-sync-storage";
syncWithSessionStorage();
```
Every function will return a new function to unsubscribe for cache changes.