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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pitboxdev/dynamic-store-zustand

v0.1.4

Published

Dynamic store factory built on top of Zustand for scalable state management

Downloads

902

Readme

@pitboxdev/dynamic-store-zustand

Dynamic store factory for ZustanduseState-like ergonomics with the power of a global shared registry.


🚀 Live Demo

  • Basic Demo – Theme toggling, cross-branch state updates, and complex reset scenarios.

⚡ Simplicity First

const { data, setData } = useDynamicStore('user', { initialState });

That's it. No stores to define, no boilerplate. Just useState ergonomics with the full power of Zustand.


🚀 Quick Start

1. Installation

npm install @pitboxdev/dynamic-store-zustand zustand

2. Initialization (Optional)

If you need to provide initial state or custom middlewares, initialize the manager in your entry point. Otherwise, it will be initialized automatically with defaults on first hook call.

import { createDynamicStore } from "@pitboxdev/dynamic-store-zustand";

// Optional: Provide initial global state or custom middlewares
createDynamicStore({
  initialState: { theme: 'dark' },
  devTools: true,
  middlewares: [loggerMiddleware]
});

3. Basic Usage

import { useDynamicStore } from "@pitboxdev/dynamic-store-zustand";

interface UserState { name: string; score: number }

function Profile() {
  const { 
    data,       // Current state (or selected part)
    setData,    // Update state (shallow merge)
    reset,      // Reset to initial state
    getData,    // Sync getter (avoids re-renders in callbacks)
  } = useDynamicStore<UserState>(
    "user",                        // 1. Store ID (must be unique)
    {                              // 2. Configuration Object
      initialState: { name: "Guest", score: 0 },
      persistOnNavigation: true,   // Keep state when changing routes
      resetOnUnmount: true,        // Reset state when component unmounts
      navigationGroups: ["auth"],  // Tag for selective bulk reset
    },
    (state) => state               // 3. Optional Selector (for performance)
  );

  return (
    <div>
      <p>{data.name}: {data.score}</p>
      <button onClick={() => setData((prev) => ({ score: prev.score + 1 }))}>
        +1 Score
      </button>
      <button onClick={reset}>Reset</button>
    </div>
  );
}

🧹 Cleanup & Navigation

By default, dynamic stores are persistent. You can trigger cleanup manually when the route changes or when a component unmounts.

Config Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | persistOnNavigation | boolean | false | If true, state is NOT reset when resetDynamicStores("non-persistent") is called. | | navigationGroups | string[] | — | Tags for grouping stores. Allows for selective bulk resets (e.g., reset all "UI" stores but keep "User" stores). | | resetOnUnmount | boolean | false | Automatically reset state when the component calling useDynamicStore is unmounted. |

Why use navigationGroups?

Grouping stores is powerful for managing complex state lifetimes. Instead of resetting stores one by one, you can categorize them:

  • Example 1: The Multi-Step Form Tag all stores in a checkout flow with navigationGroups: ["checkout"]. When the user finishes or cancels, call resetDynamicStores(["checkout"]) to clean up everything at once.
  • Example 2: Global UI State Tag modals, sidebars, and filters with navigationGroups: ["ui"]. You can then reset all UI elements during navigation while keeping data stores alive.

Manual & Selective Reset

import { resetDynamicStores } from "@pitboxdev/dynamic-store-zustand";

// 1. Basic navigation cleanup:
// Resets everything EXCEPT stores with { persistOnNavigation: true }
resetDynamicStores("non-persistent"); 

// 2. The "Logout" pattern:
// Resets absolutely every dynamic store to its initial state.
resetDynamicStores("all"); 

// 3. Selective reset by Tag:
// Resets only stores that have "checkout" in their navigationGroups.
resetDynamicStores(["checkout"]); 

// 4. Reset with Exclusions:
// Resets everything but skip stores tagged with "user-settings" or "theme".
resetDynamicStores("all", { excludeGroups: ["user-settings", "theme"] });

⚓ Router Integration

To trigger cleanup only on transitions (skipping the first render), use a ref guard:

const isFirstRender = useRef(true);

useEffect(() => {
  if (isFirstRender.current) {
    isFirstRender.current = false;
    return;
  }
  resetDynamicStores("non-persistent");
}, [location.pathname]);

🛠️ Advanced Features

Optimizing Re-renders

Pass a selector as the third argument to subscribe only to specific state changes:

const { data: score } = useDynamicStore("user", config, (s) => s.score);

Subscriptions-free access

Use useDynamicStoreMethods to get setters and getters without subscribing to state changes (prevents re-renders).

const { setData, getData } = useDynamicStoreMethods<UserState>("user");

🤝 Need Professional Help?

Available for technical collaboration on React/Zustand architecture and custom project development. Contact: [email protected]


License

MIT © Pitboxdev