# pinia-shared-state

Latest version **2.1.0** (published 2026-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install pinia-shared-state
pnpm add pinia-shared-state
yarn add pinia-shared-state
bun add pinia-shared-state
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-10-09 |
| First published | 2021-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 300 |
| Author | Robert Soriano |
| Maintainers | wobsoriano |

## Links

- npm: https://www.npmjs.com/package/pinia-shared-state
- Repository: https://github.com/wobsoriano/pinia-shared-state
- Funding: https://github.com/sponsors/wobsoriano
- npm.io page: https://npm.io/package/pinia-shared-state

## Dependencies (1)

- [broadcast-channel](https://npm.io/package/broadcast-channel.md) ^7.3.0

## Recent versions

- 2.1.0 (latest) — 2026-10-09
- 2.0.1 — 2026-03-24
- 2.0.0 — 2026-03-24
- 1.0.1 — 2025-02-12
- 1.0.0 — 2025-02-12
- 0.5.1 — 2023-12-15
- 0.5.0 — 2023-12-13
- 0.4.5 — 2023-06-22
- 0.4.4 — 2023-06-21
- 0.4.3 — 2023-06-21
- 0.4.2 — 2023-06-15
- 0.4.1 — 2023-06-15
- 0.4.0 — 2023-06-14
- 0.3.0 — 2023-01-30
- 0.2.14 — 2023-01-24
- … 27 more at https://npm.io/package/pinia-shared-state/versions

## README

# pinia-shared-state

Sync your Pinia state across browser tabs.

## Requirements

- pinia ^3.0.0 || ^4.0.2

## Install

```sh
npm install pinia-shared-state
```

## Usage

```js
import { PiniaSharedState } from 'pinia-shared-state';

// Pass the plugin to your application's pinia plugin
pinia.use(
  PiniaSharedState({
    // Enables the plugin for all stores. Defaults to true.
    enable: true,
    // If set to true this tab tries to immediately recover the shared state from another tab. Defaults to true.
    initialize: false,
    // Enforce a type. One of native, idb, localstorage or node. Defaults to native.
    type: 'localstorage',
  }),
);
```

```js
const useStore = defineStore({
  id: 'counter',
  state: () => ({
    count: 0,
    foo: 'bar',
  }),
  share: {
    // An array of fields that the plugin will ignore.
    omit: ['foo'],
    // Override global config for this store.
    enable: true,
    initialize: true,
  },
});
```

Vanilla usage:

```ts
import { share } from 'pinia-shared-state';
import { onMounted, onUnmounted } from 'vue';
import useStore from './store';

const counterStore = useStore();

onMounted(() => {
  const { unshare } = share('counter', counterStore, { initialize: true });

  onUnmounted(() => {
    // Call `unshare` method to close the channel
    unshare();
  });
});
```

## License

MIT

---
_Source: https://npm.io/package/pinia-shared-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
