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

state-signal

v0.1.3

Published

A minimal signal based state management solution with cherrys on top!

Readme

State Signal

A minimal signal based state management solution with cherrys on top!

Features

  • Framework Agnostic
  • Automatic Dependency Tracking In Effects
  • Exposes createSignal, derived and effect primitives
  • Provides signal history or snapshots
  • Lightweight, Zero Dependencies, Type Safe!

Installation

npm install state-signal

Usage With React

  1. Make sure you already have your react project setup and react installed.
  2. Install state-signal using npm or yarn.
  3. At your project root create a store.ts file.
  4. Define and export your signals in the store.ts file.

In case you get an error like Error: useSyncExternalStore only works in Client Components. Add the "use client" directive at the top of the file to use it. Please do it and add the "use client" directive at the top of every file where your using the useSignal hook as it uses useSyncExternalStore react hook under the hood to effectively sync signal values with react components.

// store.ts
import { createSignal, derived } from 'state-signal';

export const counterSignal = createSignal(0);
export const userSignal = createSignal(null);
  1. Import and use your signals in your components via useSignal hook as below.
// page.tsx
import { useSignal } from 'state-signal';
import { counterSignal, userSignal } from './store';

function Counter() {
  const [count, setCount] = useSignal(counterSignal);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      {/* you can also still update a signal directly no problem */}
      <button onClick={() => counterSignal.value -= 1}>Decrement</button>
    </div>
  );
}

function User() {
  const [user, setUser] = useSignal(userSignal);
  console.log(userSignal.histroy()); // []
  return (
    <div>
      <p>User: {user ? user.name : 'Guest'}</p>
      <button onClick={() => setUser({ name: 'John Doe' })}>Login</button>
    </div>
  );
}

Core Usage, No Framework Just Vanilla JavaScript!

1. Basic Signals

Create and manage reactive state with simple signal premitive.

import { createSignal } from 'state-signal';

// Counter example
const counter = createSignal(0);

// Get initial value
console.log(counter.value); // Logs: 0

// Update the value
counter.value += 1;
console.log(counter.value); // Logs: 1

2. Derived Signals

Automatically compute values based on other signals.

import { createSignal, derived } from 'state-signal';

// Signals for first name and last name
const firstName = createSignal("John");
const lastName = createSignal("Doe");

// Derived signal to compute full name
const fullName = derived(() => `${firstName.value} ${lastName.value}`);

console.log(fullName.value); // Logs: "John Doe"

// Update one of the signals
firstName.value = "Jane";
console.log(fullName.value); // Logs: "Jane Doe"

Note: derived signals can't be directly updated, as in derivedSignal.value = something is not allowed to mantain semantics.

3. Effects

Effects run whenever signals they depend on change.

import { createSignal, effect } from 'state-signal';

// Signal to track room temperature
const roomTemperature = createSignal(25);

// Effect to log temperature changes, runs everytime we update roomTemperature signal
effect(() => {
  console.log(`Temperature updated: ${roomTemperature.value}°C`);
});

// Update the temperature, triggering the effect
roomTemperature.value = 28; // Logs: "Temperature updated: 28°C"
roomTemperature.value = 22; // Logs: "Temperature updated: 22°C"

4. Signal History

Track and access past states of a signal, configurable per signal.

import { createSignal } from 'state-signal';

// Signal to track a movie series' release years with history enabled
const movieReleaseYears = createSignal(2001, { history: true, maxHistory: 3 });

// Update release years to build a history
movieReleaseYears.value = 2002; // First sequel
movieReleaseYears.value = 2005; // Second sequel
movieReleaseYears.value = 2010; // Third sequel

// Access history
console.log(movieReleaseYears.history(-1)); // Logs: 2010 (most recent value)
console.log(movieReleaseYears.history(-2)); // Logs: 2005 (second most recent value)
console.log(movieReleaseYears.history()); // Logs: [2002, 2005, 2010] (entire history)

// Exceeding maxHistory
movieReleaseYears.value = 2020; // Fourth sequel, oldest entry removed
console.log(movieReleaseYears.history()); // Logs: [2005, 2010, 2020]

// Out-of-bounds access
console.log(movieReleaseYears.history(-5));
// Logs: "state signal error: Requested history index (-5) exceeds current size (3)..."

// Signal without history
const singleYearSignal = createSignal(1995, { history: false });
console.log(singleYearSignal.history(-1));
// Logs: "History is deactivated for this signal."

Note: by default history is enabled for each signal and upto 10 snapshots by default.

Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push to the branch: git push origin feature/new-feature
  5. Submit a pull request

Quality Checks

Before each PR is merged, the following checks are automatically run:

  • TypeScript type checking
  • ESLint validation
  • Unit tests
  • Export validation
  • Bundle size checks

See the GUIDE for more info!

License

MIT License - see the LICENSE file for details

Support

Built with ❤️ By Hussein Kizz