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 🙏

© 2025 – Pkg Stats / Ryan Hefner

use-react-signals

v1.0.3

Published

Replace useState with useSignal and forget about performance issues

Readme

use-react-signals

Simplify shared state management and boost React performance by replacing useState with useSignals.

  • 🌎 Efficient Shared State: Seamlessly share state through props or context without triggering unnecessary re-renders.
  • ☘️ Incremental Adoption: Gradually replace useState with useSignals where it benefits your application.
  • 🧠 Familiar Mental Model: Maintain the intuitive React patterns you already know for state updates, effects, and memoization.
  • 🎈 Transparent Implementation: Clear, simple, and readable implementation that you can understand.

Installation

npm install use-react-signals

Enable Observation Mode

Observation Mode makes components observers of signals and allows for targeted reconciliation. Use the provided plugins to automatically enable this mode:

Babel Plugin

import babelPlugin from "use-react-signals/babel-plugin";

SWC Plugin

import swcPlugin from "use-react-signals/swc-plugin";

Basic Example

Here's a minimal example demonstrating how useSignals works:

import { useSignals } from "use-react-signals";

// Does not re-render on `count` changes
function Counter() {
  const [counter, setCounter] = useSignals({
    count: 0,
    increment() {
      setCounter({ count: counter.count + 1 });
    },
  });

  return (
    <>
      <Count counter={counter} />
      <Incrementer counter={counter} />
    </>
  );
}

// Re-renders only when `count` changes
function Count({ counter }) {
  return <h1>My count is: {counter.count}</h1>;
}

// Does not re-render on `count` changes
function Incrementer({ counter }) {
  return <button onClick={counter.increment}>Increment</button>;
}

Using Signals with React Context

You can easily expose shared state via context with signals:

import { createContext, useContext } from "react";
import { useSignals } from "use-react-signals";

const AppStateContext = createContext(null);

export function useAppState() {
  return useContext(AppStateContext);
}

export function AppStateProvider({ children }) {
  const [state, setState] = useSignals({
    count: 0,
    increment() {
      setState({ count: state.count + 1 });
    },
  });

  return (
    <AppStateContext.Provider value={state}>
      {children}
    </AppStateContext.Provider>
  );
}

How It Works

useSignals returns an object whose reference never changes, significantly reducing unnecessary re-renders caused by changes in props or context references. The methods returned by useSignals also retain stable references. Components re-render only when they explicitly access signal keys that updates.

Observation Mode, enabled by the Babel or SWC plugins, makes components observers of signals, allowing targeted reconciliation and improving performance by avoiding unnecessary re-renders.

Did you know?

  • You can use useSignals for local component state if you prefer it
  • You can safely perform asynchronous state changes in effects as the component stops subscribing to signals when it unmounts
  • You can use useSignals with useMemo and useEffect as normal