Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dlurak/svocal

Localstorage With The Power Of Svele Stores
https://github.com/dlurak/svocal

localstorage svelte sveltekit

Last synced: about 1 month ago
JSON representation

Localstorage With The Power Of Svele Stores

Awesome Lists containing this project

README

        

# Svocal

Svocal combines the power of Svelte stores with localstorage.

## Installation

```bash
npm i svocal
```

```bash
yarn add svocal
```

```bash
pnpm add svocal
```

```bash
bun add svocal
```

## Usage

Import `localstorage`:

```ts
import { localstorage } from 'svocal';
```

Then you can start using the localstorage:

```ts
const store = = localstorage('demo', 1)
const store2 = = localstorage('demo', 1)
```

`store` and `store2` both use the localstorage key `demo` so when you set store store2 will also update.

```ts
store.set(42);
store2.subscribe(console.log);
```

Will console.log 42

This even works with different tabs, so svocal can be used to sync state between tabs and windows!