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

@topojs/react

v0.2.5

Published

React hooks for TopoJS — useNode, useNodes, useMutation, useTopology

Readme

@topojs/react

React hooks for TopoJS — subscribe to graph-topology state from React components.

Installation

npm install @topojs/react @topojs/core

Requirements

  • React >= 18
  • Node.js >= 20

Overview

@topojs/react provides React hooks built on useSyncExternalStore for reading and mutating state managed by a @topojs/core statespace. Pass the RuntimeStatespace instance directly into any hook.

Hooks

useNode(space, path)

Subscribe to a single node. Re-renders only when that value changes.

const total = useNode<number>(CartSpace, 'total');

useNodes(space, paths)

Subscribe to multiple nodes at once. Returns a stable array reference when values are unchanged.

const [items, discount, total] = useNodes<[Item[], number, number]>(CartSpace, [
  'items',
  'discount',
  'total',
]);

useMutation(space, path)

Returns memoized write helpers for a node.

const { set, update, append } = useMutation(CartSpace, 'items');

// set a new value
set([]);

// functional update
update((prev) => [...prev, newItem]);

// append to an array node
append(newItem);

useTopology(space, path)

Returns memoized topology metadata for a node — useful for debugging or rendering dependency graphs.

const { dependsOn, affects, updateOrder } = useTopology(CartSpace, 'total');
// dependsOn   → ['items', 'discount']
// affects     → ['canCheckout']
// updateOrder → ['total', 'canCheckout']

useTopologyEvent(space, event, handler)

Subscribe to a topology event. Cleans up automatically on unmount.

useTopologyEvent(CartSpace, 'influenced', ({ path, sources }) => {
  console.log(`${path} was influenced by`, sources);
});

useTopologyEvent(CartSpace, 'slow-propagation', ({ path, ms }) => {
  console.warn(`Slow propagation on ${path}: ${ms}ms`);
});

Usage pattern

Define the statespace once at module level, then pass it into hooks:

// store.ts
import { statespace, node, derives } from '@topojs/core';

export const CartSpace = statespace('Cart', {
  nodes: {
    items: node({ initial: [] as number[] }),
    total: node({ initial: 0 }),
  },
  topology: {
    total: derives(['items'], (items) => (items as number[]).reduce((a, b) => a + b, 0)),
  },
});

// Cart.tsx
import { useNode, useMutation } from '@topojs/react';
import { CartSpace } from './store';

export function Cart() {
  const total = useNode<number>(CartSpace, 'total');
  const { append } = useMutation(CartSpace, 'items');

  return (
    <div>
      <p>Total: {total}</p>
      <button onClick={() => append(10)}>Add item</button>
    </div>
  );
}

License

MIT