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

statezero-react-hooks

v0.1.0

Published

React hooks for Statezero

Readme

statezero-react-hooks

npm version CI License: MIT

React hooks for statezero.

Getting Started

Install from npm.

npm install react statezero statezero-react-hooks --save

statezero-react-hooks is packaged as both ESM and UMD bundles:

ES6 Module (Recommended)

import { useStatezero, useStatezeroPath } from "statezero-react-hooks";

ES6 Module from Source

Import directly from unbundled source files for maximum flexibility:

// Note that the import path ends with '/src'
import { useStatezero, useStatezeroPath } from "statezero-react-hooks/src";

This gives your bundler complete control over transpilation and tree-shaking.

Browser Global

<script src="./node_modules/statezero/dist/statezero.js"></script>
<script src="./node_modules/statezero-react-hooks/dist/statezero-react-hooks.js"></script>
<script>
  const { useStatezero } = window.statezeroReactHooks;
</script>

Usage

useStatezero(selector, isSync)

Subscribe to state changes matching the selector. Returns the current selected state value.

  • selector - Optional. A string path, array of paths, or selector function (see statezero selectors)
  • isSync - Optional. If true, updates are synchronous; otherwise debounced (default: false)
import { useStatezero } from "statezero-react-hooks";

function Counter() {
  const count = useStatezero("count");
  return <div>Count: {count}</div>;
}

function UserProfile() {
  const user = useStatezero((state) => state.user);
  return <div>Hello, {user?.name}</div>;
}

useStatezeroPath(path, isSync)

Subscribe to a specific path in state. Returns a [value, setValue] tuple similar to React's useState.

  • path - Required. A dot notation string path (e.g., "count", "user.name", "deeply.nested.value"). Unlike useStatezero, this hook does not accept function or array selectors.
  • isSync - Optional. If true, updates are synchronous; otherwise debounced (default: false)
import { useStatezeroPath } from "statezero-react-hooks";

function Counter() {
  const [count, setCount] = useStatezeroPath("count");
  return (
    <div>
      <span>Count: {count}</span>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

function NestedValue() {
  const [value, setValue] = useStatezeroPath("deeply.nested.value");
  return (
    <input value={value || ""} onChange={(e) => setValue(e.target.value)} />
  );
}

Sync Variants

By default, state change notifications are debounced to the next tick. Use the sync variants for immediate updates:

import { useStatezeroSync, useStatezeroPathSync } from "statezero-react-hooks";

const count = useStatezeroSync("count");
const [value, setValue] = useStatezeroPathSync("path.to.value");

Selector Stability

When using function or array selectors, define them outside the component or memoize them to avoid resubscribing on every render:

// Good: selector defined outside component
const selectUser = (state) => state.user;

function UserProfile() {
  const user = useStatezero(selectUser);
  return <div>{user?.name}</div>;
}

// Good: memoized selector
function FilteredItems({ category }) {
  const selector = useMemo(
    () => (state) => state.items.filter((i) => i.category === category),
    [category],
  );
  const items = useStatezero(selector);
  return (
    <ul>
      {items.map((i) => (
        <li key={i.id}>{i.name}</li>
      ))}
    </ul>
  );
}

String path selectors (e.g., "user.name") don't have this issue since strings are primitives.

API Reference

| Hook | Arguments | Returns | Description | | ---------------------- | ---------------------- | ----------------- | ------------------------------------------------- | | useStatezero | (selector?, isSync?) | value | Subscribe to state, return selected value | | useStatezeroSync | (selector?) | value | Synchronous version of useStatezero | | useStatezeroPath | (path, isSync?) | [value, setter] | Subscribe to string path, return value and setter | | useStatezeroPathSync | (path) | [value, setter] | Synchronous version of useStatezeroPath |

Developing

npm install
npm run build        # Development build (UMD + ESM)
npm run format       # Format code with prettier
npm run lint         # ESLint with zero-warning policy
npm run test         # Run tests with Jest
npm run test:watch   # Run tests in watch mode
npm run size         # Check bundle size limits

Publishing

npm version minor    # or major/patch - updates package.json and creates git tag
git push && git push --tags
npm publish

Related Projects

  • statezero - The core state management library