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-alien-signals

v0.4.0

Published

Concurrency-safe React hooks for Alien Signals

Downloads

843

Readme

React Alien Signals

License npm Build

React Alien Signals is a TypeScript library that provides hooks built on top of Alien Signals. It offers a seamless integration with React, ensuring concurrency-safe re-renders without tearing.

API reference

Table of Contents

Features

  • Basic Signals: Create and manage reactive state with createSignal
  • Computed Signals: Derive reactive values based on other signals using createComputed
  • Effects & Effect Scopes: Run side effects in response to state changes with createEffect and manage multiple effects with createSignalScope
  • Tear-free React integration: Shares stable useSyncExternalStore adapters between subscribers
  • Selective subscriptions: Avoid unrelated renders with useSignalSelector
  • Concurrent UI tools: Defer signal-driven UI with useDeferredSignalValue
  • Lifecycle effects: Run explicit signal dependencies in React's insertion, layout, or passive phase
  • Batching: Coalesce multiple signal writes with batch
  • React Compiler compatible: Every exported hook is checked by React Compiler in CI
  • TypeScript Support: Fully typed APIs for type safety and IntelliSense

Installation

Install react-alien-signals and its peer dependency alien-signals via npm:

npm install react-alien-signals alien-signals

The current release line targets React 19.2 or newer and Alien Signals 3.2.

Usage

Basic Signals

Create a writable signal and use it within your components:

import { createSignal, useSignal } from "react-alien-signals";

const count = createSignal(0);

function Counter() {
  const [value, setValue] = useSignal(count);

  return (
    <button onClick={() => setValue(value + 1)}>
      Count: {value}
    </button>
  );
}

Computed Signals

Create derived state that automatically updates:

import { createSignal, createComputed, useSignalValue } from "react-alien-signals";

const count = createSignal(1);
const double = createComputed(() => count() * 2);

function Display() {
  const doubleValue = useSignalValue(double);
  return <div>Double: {doubleValue}</div>;
}

Effects & Effect Scopes

Run side effects in response to signal changes:

import { createSignal, createEffect, useSignalScope } from "react-alien-signals";

const count = createSignal(0);

function Logger() {
  useSignalScope(() => {
    createEffect(() => {
      console.log('Count changed:', count());
    });
  });

  return null;
}

React Hooks

React Alien Signals provides several hooks to interact with signals:

  • useSignal(signal): Returns [value, setValue] tuple for reading and writing
  • useSignalValue(signal): Returns the current value (read-only)
  • useDeferredSignalValue(signal): Returns a deferred signal snapshot
  • useSignalSelector(signal, selector): Subscribes only to the selected value
  • useSetSignal(signal): Returns a setter function (write-only)
  • useSignalEffect(effectFn): Runs a side effect based on signal changes
  • useSignalPassiveEffect(signals, effectFn, deps?): Runs explicit signal dependencies in React's passive phase
  • useSignalLayoutEffect(signals, effectFn, deps?): Runs explicit signal dependencies in React's layout phase
  • useSignalInsertionEffect(signals, effectFn, deps?): Runs explicit signal dependencies in React's insertion phase
  • useSignalScope(callback): Manages effect scopes within a component
  • useComputed(getter, deps): Creates and subscribes to a computed signal

useComputed(getter, deps)

The dependency array follows the same rules as useMemo.

function Component({ a }) {
  useComputed(
    () => {
      return a + mySignal();
    },
    [a, mySignal],
  );
}

Batching writes

import { batch } from "react-alien-signals";

batch(() => {
  firstName("Ada");
  lastName("Lovelace");
});

Concurrent Rendering

Signal snapshots remain consistent across concurrent React renders through useSyncExternalStore. External-store writes are synchronous by React's design, including when they happen inside startTransition; use useDeferredSignalValue when a signal-driven subtree may render later.

React automatically batches component renders caused by multiple signal writes in the same event or task. Most application code therefore needs no batching API. Use batch only when you also need to prevent intermediate Alien Signals computed values and effects from propagating between a group of writes.

useOptimistic is best kept for Action-owned optimistic state rather than used as a second signal store. Effect scopes start only after a component commits, so server rendering and abandoned renders do not leak effects. Lifecycle-specific signal effects require an explicit, referentially stable signal list so React can run them in the requested phase.

Benchmarks

Run the local comparison against raw React state, TanStack Store, Jotai, and Zustand:

bun run benchmark

Representative local results on Apple Silicon with Bun 1.3.14 and React 19.2.8:

| Scenario | React Alien Signals | Raw React | Zustand | TanStack | Jotai | | --- | ---: | ---: | ---: | ---: | ---: | | One commit per write | 200–214k/s | 193–242k/s | 183–213k/s | 133–213k/s | 114–140k/s | | 10k writes, React auto-batched | 12.4–13.0M/s | 14.0–15.7M/s | 9.5–12.2M/s | 6.9–8.1M/s | 0.68–0.74M/s | | 10k writes, signal graph batched | 46.4–57.8M/s | — | — | — | — |

Each range covers three runs. Every batched case validates the final value and exactly one update render. batch also collapses intermediate computed and effect propagation; React's automatic batching only collapses renders.

Contributing

See CONTRIBUTING.md for local setup and pull request checks.

License

MIT

Acknowledgements