sergiodxa / swr-sync-storage Goto Github PK
View Code? Open in Web Editor NEWSynchronize SWR cache with localStorage or sessionStorage to get offline cache
License: MIT License
Synchronize SWR cache with localStorage or sessionStorage to get offline cache
License: MIT License
Hi, if I use load more scroll, that will be much data in localstorage.
I hope you can edit more to archive which key should we cache
I want something like this
import { syncWithStorage } from "swr-sync-storage";
syncWithStorage("local",["key-i-want-to-save"]); // this key just in localstorage, not in session too. And regex will be more great i think
syncWithStorage("session",["key-i-want-to-save"]);
key serialization: https://github.com/vercel/swr/blob/master/src/cache.ts#L45
think of the using as follow
function App() {
const {data} = useSWR('/api/a');
const {data} = useSWR(['/api/list', {id: data.id}], fetcher);
}
the key may serialize to /api/list0
,
{name: 'xxx', age: 'xxx'} will transform to a Incremental number
page1
function App() {
const {data} = useSWR(['/api/list', {id: '1'}], fetcher);
}
page2
function App() {
const {data} = useSWR(['/api/list', {id: '2'}], fetcher);
}
when i open page1 and page2, ['/api/list', {id: '1'}]
and ['/api/list', {id: '2'}]
will be serialized to /api/list0
, but they stand for a different query. so they may use the error data
Hi. I keep stumbling across this repo and your comments on other peoples issues.
It seems this packages is not maintained anymore - could you recommend any alternatives?
I have already tried react query, but prefer SWR, but maybe you know of others?
Kind regards
Dennis
Hi, I have this error when check user data in. Did you face with this problem?
Warning: Prop `className` did not match. Server: "navbar-item is-hidden" Client: "navbar-item"
<Link href="/user" as="/user">
<a className={ user? "navbar-item" : "navbar-item is-hidden" }>
Dashboard
</a>
</Link>
Hi can you make a simple example for use this? I am trying to save public user info to local.
I use localStorage with SWR but it not work well.
would you be openminded to add a couple more storage systems?
Cache api (works inside WebWorkers and persists to webapps added to home screen in iOS) https://developer.mozilla.org/en-US/docs/Web/API/Cache
Dexie.js with IndexedDB (enables multiple databases, bigger amounts of data, queries, search etc)
https://dexie.org
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.