@svackages/persistent-store
v1.0.3
Published
![svackages logo](https://raw.githubusercontent.com/svackages/persistent-store/main/logo.png) # persistent typed store This package allows you to persist your store through localstorage.
Downloads
1
Readme
persistent typed store
This package allows you to persist your store through localstorage.
basic usage
Typescript
const myPersistentStore = persistentStore<SomeType>({
key: 'fancyKey',
initValue: null,
});
JavaScript
const myPersistentStore = persistentStore({
key: 'fancyKey',
initValue: null,
});
clear out localstorage
// in .svelte
$myPersistentStore = null; // undefined will work as well
// in .ts/.js
myPersistentStore.set(null); // undefined will work as well
optional params
you can hook into the read and write cycle to transform values.
readHook?: (storage?: string) => T,
writeHook?: (storeValue: T) => string