Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 month 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 (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-25T10:01:14.000Z (almost 2 years ago)
- Last Synced: 2024-10-16T10:41:45.324Z (about 2 months ago)
- Topics: localstorage, sessionstorage, swr, swr-sync-storage, web-storage
- Language: TypeScript
- Size: 1.06 MB
- Stars: 110
- Watchers: 3
- 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
![CI](https://github.com/sergiodxa/swr-sync-storage/workflows/CI/badge.svg)
![Publish](https://github.com/sergiodxa/swr-sync-storage/workflows/Publish/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/24f2981243f767aba3e8/maintainability)](https://codeclimate.com/github/sergiodxa/swr-sync-storage/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/24f2981243f767aba3e8/test_coverage)](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.