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

@piplup/react-store

v0.0.1

Published

Context-scoped React state management that lives in your component tree instead of as a global singleton. Uses useSyncExternalStore internally but gives you Provider-bound, selector-driven stores with stable actions — no external subscriptions, no hydrati

Downloads

32

Readme

@piplup/react-store

Context-scoped React state management that lives in your component tree instead of as a global singleton.

The problem

Most state managers are built around a single global store that lives outside React. Because that store is shared across your whole app, your tests, and even your requests, it causes bugs:

  • Stale state across screens — a global store survives navigation, so the next view can read the previous view's state.
  • SSR hydration mismatches — an external store is populated from server code, so the server-rendered markup can differ from what React's provider tree produces on the client.
  • Test pollution — one test mutates the shared store; the next test starts from that leftover state unless you remember to reset globals.
  • No isolation — you cannot cheaply mount the same feature twice (for example two independent checkouts), because there is only "the" store.

What this package does differently

Instead of a module-level singleton, each <Provider> creates an isolated store instance that lives and dies with its component tree. Selectors, subscriptions, and actions are all managed internally through useSyncExternalStore, but none of that leaks into your code.

This means:

  • No singleton module shared across your app.
  • Multiple providers of the same store type are fully independent.
  • No external subscription boilerplate in consuming components.
  • No hydration mismatch in SSR (the store exists only inside React).

useStore subscribes to a slice of state through a selector. useActions returns actions that keep a referentially stable identity for the lifetime of the provider.

Features

  • Provider-scoped, not global — each <store.Provider> is its own isolated store; no singleton shared across your bundle.
  • Selector-driven re-renders — a component re-renders only when the selected value changes (Object.is), without you wiring up useSyncExternalStore.
  • Stable actions — actions are created once per provider and never change identity.
  • SSR-safe — the store exists entirely inside React, so there is no external state that hydrates out of sync.
  • compose for nesting providers into a single component.
  • Zero runtime dependencies (React only).
  • ESM-only, fully typed (.d.ts included).

Requirements

  • Node.js >= 18
  • React >= 18 (useSyncExternalStore)

Installation

# pnpm
pnpm add @piplup/react-store

# npm
npm install @piplup/react-store

# yarn
yarn add @piplup/react-store

Quick Start

Define a store with its initial state shape and its actions:

import { defineStore } from '@piplup/react-store';

interface CounterState {
  count: number;
}

const counter = defineStore<CounterState>('counter')((set) => ({
  increment: () => set((state) => ({ count: state.count + 1 })),
  reset: () => set({ count: 0 })
}));

Mount a provider with the initial state:

<counter.Provider initialState={{ count: 0 }}>
  <App />
</counter.Provider>

Read state with the useStore hook. Pass a selector to subscribe to a slice of the state:

function Count() {
  const count = counter.useStore((state) => state.count);

  return <div>{count}</div>;
}

Mutate state through actions:

function Controls() {
  const actions = counter.useActions();

  return <button onClick={actions.increment}>Increment</button>;
}

You can also read the whole state (no selector):

const state = counter.useStore();

Hooks throw if used outside of their provider:

counter: useStore must be used within <counter.Provider>.

Composing Providers

Use compose to wrap a component with any number of providers in a single, memoized component:

import { compose, provider } from '@piplup/react-store';

const App = compose(
  provider(counter.Provider, { initialState: { count: 0 } }),
  provider(ThemeProvider, { theme })
)(Root);

provider wraps a component and, optionally, its props. compose renders the innermost provider first: the last provider passed to compose wraps the component directly.

API

defineStore<TState>(name)

Returns a function that accepts an action factory:

defineStore<TState>(name).(createActions: (set) => TActions)

and returns:

  • Provider<Provider initialState={...}>{children}</Provider>. initialState is an initializer, not a syncing value.
  • useStore() — returns the whole state.
  • useStore<TResult>(selector) — subscribes to a selected value; re-renders only when the selected value changes.
  • useActions() — returns the actions object (stable identity).

provider(Component, props?)

A ProviderDefinition helper for compose.

compose(...providers)(Component)

Wraps Component in the given providers, innermost-last.

License

Apache-2.0