Socket
Socket
Sign inDemoInstall

swr-sync-storage

Package Overview
Dependencies
8
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

swr-sync-storage

Synchronize SWR cache with localStorage or sessionStorage to get offline cache


Version published
Maintainers
1
Weekly downloads
134
increased by32.67%

Weekly downloads

Readme

Source

swr-sync-storage

CI Publish Maintainability Test Coverage

Synchronize SWR cache with localStorage or sessionStorage to get offline cache.

Usage

Install it

$ yarn add swr-sync-storage

Note: You will need to provide SWR v0.2.0-beta.0 or greater

import { syncWithStorage } from "swr-sync-storage";
syncWithStorage("local");
syncWithStorage("session");

You can also import to already bound versions of local or session storage.

import { syncWithLocalStorage } from "swr-sync-storage";
syncWithLocalStorage();
import { syncWithSessionStorage } from "swr-sync-storage";
syncWithSessionStorage();

All the functions will return a function to stop subscribing for cache changes.

All functions receive a parser function to let you parse the storage value, the default value is:

function parser(value: string): any {
  return value === 'undefined' ? undefined : JSON.parse(value);
}

If your SWR cache could have non-object values such as numbers you could pass a custom parser and control how syncWithStorage will transform it before adding it to SWR.

FAQs

Last updated on 01 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc