npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sync-tabs-zustand

v0.2.1

Published

Zustand middleware to easily sync Zustand state between tabs and windows

Downloads

9

Readme

Zustand Sync Tabs Version Downloads npm bundle size

Zustand middleware to easily sync Zustand state between tabs/windows / iframes (Same Origin)

  • ✅ 🐙 ~ 1 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
  • ✅ Partial state sharing is also supported

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.

Install

$ pnpm add zustand-sync-tabs

or

$ npm install zustand-sync-tabs

or

$ yarn add zustand-sync-tabs

Usage

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!

Advanced - ignore / filter out fields based on regExp

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

🤩 Don't forget to star this repo!

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

Alt

License

Licensed as MIT open source.