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-dispatch

v2.0.0

Published

Tiny, dependency-free, type-safe event dispatcher for React and JavaScript applications.

Readme

react-dispatch

A tiny, dependency-free, type-safe event dispatcher for React and JavaScript applications.

npm version license

Highlights

  • Zero runtime dependencies
  • ESM and CommonJS builds
  • Built and tested with the 2026 toolchain: TypeScript 7, Vitest 5, esbuild
  • Legacy generic API remains supported
  • Strongly typed event maps via createDispatcher
  • on() / once() return unsubscribe functions
  • Remove one callback or all listeners for an event
  • listenerCount() and clear() utilities
  • React is optional; the package works in vanilla JavaScript and Node.js too

Install

npm install react-dispatch

Quick start

import { dispatcher } from 'react-dispatch';

const unsubscribe = dispatcher.on<number>('counter:update', (value) => {
  console.log(value);
});

dispatcher.dispatch<number>('counter:update', 1);
unsubscribe();

Typed event maps

import { createDispatcher } from 'react-dispatch';

type AppEvents = {
  'user:login': { userId: string; name: string };
  'cart:count': number;
};

const appEvents = createDispatcher<AppEvents>();

appEvents.on('user:login', (user) => {
  console.log(user.name);
});

appEvents.dispatch('user:login', {
  userId: 'usr_123',
  name: 'Sam',
});

Invalid event names and payload shapes are rejected by TypeScript.

React example

import { useEffect, useState } from 'react';
import { dispatcher } from 'react-dispatch';

export function Counter() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    return dispatcher.on<number>('counter:update', (value) => {
      setCount((current) => current + value);
    });
  }, []);

  return <div>{count}</div>;
}

API

dispatcher.on<T>(event, callback)

Registers a persistent listener and returns an unsubscribe function.

dispatcher.once<T>(event, callback)

Registers a one-time listener and returns an unsubscribe function.

dispatcher.off(event, callback?)

Removes a specific callback when provided. Without a callback, removes all listeners for the event. Arrays of event names are supported.

dispatcher.dispatch<T>(event, data?)

Dispatches an event to all current listeners.

dispatcher.listenerCount(event)

Returns the number of persistent and one-time listeners for an event.

dispatcher.clear()

Removes every listener.

createDispatcher<EventMap>()

Creates an isolated dispatcher with compile-time event-name and payload validation.

Package output

  • ESM: dist/index.js
  • CommonJS: dist/index.cjs
  • Types: dist/index.d.ts
  • Source maps included
  • sideEffects: false for tree-shaking

Compatibility

  • Node.js 18+
  • Modern browsers
  • React 18 / 19+ (React is not a dependency)
  • TypeScript consumers supported; built and validated with TypeScript 7

Development

npm install
npm run typecheck
npm test
npm run build
npm run pack:check

License

ISC