
Product
Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.
zustand-sync-tabs
Advanced tools
Zustand middleware to easily sync Zustand state between tabs and windows
Zustand middleware to easily sync Zustand state between tabs/windows / iframes (Same Origin)
Check out
[persist-and-sync](https://github.com/react18-tools/persist-and-sync)if you are looking for persisting state locally over reload/refresh or after closing the site.
$ pnpm add zustand-sync-tabs
or
$ npm install zustand-sync-tabs
or
$ yarn add zustand-sync-tabs
Add the middleware while creating the store and the rest will be taken care.
import { create } from "zustand";
import { syncTabs } from "zustand-sync-tabs";
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!
In several cases you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on list of fields or regular expression.
type SyncTabsOptionsType = {
name: string;
/** @deprecated */
regExpToIgnore?: RegExp;
include?: (string | RegExp)[];
exclude?: (string | RegExp)[];
};
Example
export const useMyStore = create<MyStoreType>()(
syncTabs(
set => ({
count: 0,
_count: 0 /** skipped as it is included in exclude array */,
setCount: count => {
set(state => ({ ...state, count }));
},
set_Count: _count => {
set(state => ({ ...state, _count }));
},
}),
{ name: "example", exclude: ["_count"] },
),
);
For more details about regExp check out - JS RegExp
Want hands-on course for getting started with Turborepo? Check out React and Next.js with TypeScript and The Game of Chess with Next.js, React and TypeScrypt
Licensed as MIT open source.
with 💖 by Mayank Kumar Chaudhari
FAQs
Zustand middleware to easily sync Zustand state between tabs and windows
The npm package zustand-sync-tabs receives a total of 5,594 weekly downloads. As such, zustand-sync-tabs popularity was classified as popular.
We found that zustand-sync-tabs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.

Research
/Security News
A new npm package tests AI malware scanners with prompt injection, safety-triggering comments, context flooding, and obfuscated JavaScript.