Synchronize SWR cache with localStorage or sessionStorage to provide offline cache persistence. Version 1.0.1, stable release. Requires SWR v0.2.0-beta.0 or greater as a peer dependency. This package allows binding SWR's cache to browser storage (localStorage or sessionStorage), enabling offline support and cache persistence across sessions. It provides three importable functions: syncWithStorage (generic, takes a storage type string), syncWithLocalStorage (pre-bound to localStorage), and syncWithSessionStorage (pre-bound to sessionStorage). Unlike manual cache management, it automatically syncs SWR cache changes to storage and restores cache on reload. Supports custom JSON parsing for non-object values. TypeScript types included.
npm install swr-sync-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Import and call syncWithLocalStorage to synchronize SWR cache with localStorage.
Ensure SWR version matches the peer dependency range.
Use ES module import syntax (import ... from 'swr-sync-storage').
Include a check for 'undefined' in your custom parser or override with a safe JSON.parse.
Install SWR with version ^0.2.0-beta.0: npm install swr@^0.2.0-beta.0
Change to import statement: import { syncWithStorage } from 'swr-sync-storage'