Package Exports
- sync-tabs-zustand
- sync-tabs-zustand/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sync-tabs-zustand) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Zustand Sync Tabs

Zustand middleware to easily persist and sync Zustand state between tabs / windows / iframes (SameOrigin)
Motivation: Recently I got cought up in several issues working with persist miggleware and syncing tabs with zustand. This is a simple light weight middleware to persist and instantly share state between tabs or windows
- ✅ 🐙 (495 Bytes gZiped) < 0.5 kB size cross-tab state sharing middleware for zustand
- ✅ Full TypeScript Support
- ✅ solid reliability in 1 writing and n reading tab-scenarios (with changing writing tab)
- ✅ Fire and forget approach of always using the latest state. Perfect for single user systems
- ✅ Sync Zustand state between multiple browsing contexts
Checkout
[persistnsync](https://github.com/mayank1513/nextjs-themes/tree/main/packages/persistnsync#readme)if you are looking for persisting state locally over reload/refresh or after closing site
Install
$ pnpm add sync-tabs-zustand
# or
$ npm install sync-tabs-zustand
# or
$ yarn add sync-tabs-zustandUsage
Simply add the middleware while creating the store and the rest will be taken care.
import { create } from "zustand";
import { syncTabs } from "sync-tabs-zustand";
type MyStore = {
count: number;
set: (n: number) => void;
};
const useStore = create<MyStore>(
syncTabs(
set => ({
count: 0,
set: n => set({ count: n }),
}),
{ name: "my-channel" },
),
);⚡🎉Boom! Just a couple of lines and your state perfectly syncs between tabs/windows and it is also persisted using localStorage!
License
Licensed as MIT open source.
with 💖 by Mayank Kumar Chaudhari