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

react-containerized-state

v3.3.0

Published

Fast and minimal state container which can be used and shared across React or non-React components.

Readme

react-containerized-state

A collection of React hooks for seamlessly integrating a Container from containerized-state into your React components. These hooks provide a simple and idiomatic way to subscribe to container state and trigger updates, leveraging React's built-in useSyncExternalStore for optimal performance.

Installation

To install the react package, you can use a package manager like pnpm, npm, or yarn.

pnpm add react-containerized-state
# or
npm install react-containerized-state
# or
yarn add react-containerized-state

The Hooks

This package provides three primary hooks for working with a Container in React: useValue, useUpdate, and useComputedValue.

useValue(container)

A custom hook that subscribes a component to a Container and returns its current value. The component will automatically re-render whenever the container's state changes.

import { Container, useValue } from "react-containerized-state";

// Create a container instance outside of your component
const counterContainer = new Container(0);

const CounterDisplay = () => {
  // Subscribe to the container's value
  const count = useValue(counterContainer);

  return <h1>Current Count: {count}</h1>;
};

useUpdate(container)

A custom hook that returns a stable Updater function. This function can be used to update the container's state.

  • Updater<T> can accept a new state value or an updater function that receives the previous state.
  • The returned function is stable, meaning its reference does not change on re-renders, preventing unnecessary re-renders in child components that receive it as a prop.
import { Container, useValue, useUpdate } from "react-containerized-state";

// Create a container instance
const counterContainer = new Container(0);

const Counter = () => {
  const count = useValue(counterContainer);
  const updateCount = useUpdate(counterContainer);

  return (
    <div>
      <h1>Count: {count}</h1>
      <button onClick={() => updateCount(prev => prev + 1)}>Increment</button>
      <button onClick={() => updateCount(0)}>Reset</button>
    </div>
  );
};

useComputedValue(container)

A custom hook that subscribes to a derived value from the container's state. This is highly performant as the component only re-renders when the computed value changes, not every time the base container's value changes.

  • compute: A function that takes the container's value and returns the derived value.
  • isEqual: An optional custom equality function to compare the previous and next computed values. By default, Object.is is used.
import { Container, useComputedValue } from "react-containerized-state";

const userContainer = new Container({
  firstName: "Jane",
  lastName: "Doe",
});

const UserGreeting = () => {
  // The component only re-renders if the full name changes.
  const fullName = useComputedValue(
    userContainer,
    state => `${state.firstName} ${state.lastName}`,
  );

  return <h2>Hello, {fullName}!</h2>;
};

Example

Here's a full example demonstrating how to use all three hooks together to manage a simple todo list.

import {
  Container,
  useValue,
  useUpdate,
  useComputedValue,
} from "react-containerized-state";

// A single container to hold all our state
const todosContainer = new Container([
  { id: 1, text: "Learn React Hooks", completed: true },
  { id: 2, text: "Write some code", completed: false },
]);

const TodoList = () => {
  const todos = useValue(todosContainer);
  const updateTodos = useUpdate(todosContainer);
  const completedCount = useComputedValue(
    todosContainer,
    todos => todos.filter(todo => todo.completed).length,
  );

  const toggleTodo = id => {
    updateTodos(prevTodos =>
      prevTodos.map(todo =>
        todo.id === id ? { ...todo, completed: !todo.completed } : todo,
      ),
    );
  };

  return (
    <div>
      <h1>Todo List</h1>
      <p>
        {completedCount} of {todos.length} tasks completed.
      </p>
      <ul>
        {todos.map(todo => (
          <li
            key={todo.id}
            style={{ textDecoration: todo.completed ? "line-through" : "none" }}
            onClick={() => toggleTodo(todo.id)}
          >
            {todo.text}
          </li>
        ))}
      </ul>
    </div>
  );
};

Subscribe

A render props component that subscribes to a container and provides a computed value to its children. This offers a declarative, JSX-based alternative to the useComputedValue hook, which can be useful for separating concerns or creating reusable components.

  • container: The state container to subscribe to.
  • compute: An optional function that computes a derived value from the container's state. By default, value => value is used.
  • isEqual: An optional custom equality function to control re-renders.
  • children: A render function that receives the computed value as an argument.
import { Container, Subscribe } from "react-containerized-state";

// Create a container instance outside of your component
const userContainer = new Container({
  firstName: "Jane",
  lastName: "Doe",
});

const UserGreeting = () => (
  <Subscribe
    container={userContainer}
    compute={state => `${state.firstName} ${state.lastName}`}
  >
    {fullName => <h2>Hello, {fullName}!</h2>}
  </Subscribe>
);

Contributing

Read the contributing guide to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes.

License

This project is licensed under the terms of the MIT license.