svelte-persistent-writable
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

svelte-persistent-writable

A Svelte writable store that persists data. It supports local and session storage out-of-the-box and can easily be extended to target different storage mechanisms

NPM Package

npm install svelte-persistent-writable

Full documentation:

Working demo:

You can clone this repo and run npm run dev to see it working

Highlights

Create a writable store that persists its value using the localStorage

const myWritable = persistentWritable(0, {
	storage: localStorageAdapter('myWritable')
});

Create a writable store that persists its value using the sessionStorage

const myWritable = persistentWritable(0, {
	storage: sessionStorageAdapter('myWritable')
});

In a Svelte component, the created PersistentWritable can be used just like any other Writable store:

Here is the value:
<div>{$myWritable}</div>

Package Sidebar

Install

npm i svelte-persistent-writable

Weekly Downloads

1

Version

1.1.6

License

MIT

Unpacked Size

19.8 kB

Total Files

6

Last publish

Collaborators

  • cdellacqua