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

@rune-hub/react

v1.1.0

Published

Integrating RuneHub with React

Readme

@rune-hub/react provides React integration for the reactive rune-hub store, implementing a flexible subscription mechanism for state changes and mutation calls via specialized hooks. The HubProvider component injects the store instance into the React context, while the useRune and useAction hooks ensure reactive data synchronization and stable references to action functions, minimizing unnecessary re-renders. With full TypeScript support and straightforward integration, the library enables predictable state management architecture without boilerplate, while maintaining high performance and compatibility with modern build tools.

stars watchers

Index

[ Install ]
[ Examples ] Basic CounterTodo List
[ API ] HubProvideruseRuneuseSlotuseOnuseActionuseHubuseGetSlot
[ Links ]

Install

🏠︎ / Install

Requires React 18+ and rune-hub 1.0+.

Use with any modern bundler (Vite, Webpack, Rollup, etc.) or framework (Next.js, Remix, etc.).

npm i rune-hub @rune-hub/react

Examples

🏠︎ / Examples

Basic CounterTodo List

Basic Counter

🏠︎ / Examples / Basic Counter

A simple counter demonstrating.

import { slot } from 'rune-hub'
import { useRune } from '@rune-hub/react'

const count = () => 0
const increment = () => slot(count).value++
const decrement = () => slot(count).value--

function Counter () {
  const value = useRune(count)

  return (
    <div>
      <button onClick={decrement}>-</button>
      <span>{value}</span>
      <button onClick={increment}>+</button>
    </div>
  )
}

Todo List

🏠︎ / Examples / Todo List

A todo list showcasing rune-hub features.

Store:

import { get, set, update } from 'rune-hub'

export interface Todo {
  id: number
  text: string
  done: boolean
}

let nextId = 1
export const todos = (): Todo[] => []

export const addTodo = (text: string) => {
  get(todos).push({ id: nextId++, text, done: false })
  update(todos)
}

export const toggleTodo = (todoId: number) => {
  set(todos, get(todos).map(todo =>
    todoId === todo.id ? { ...todo, done: !todo.done } : todo,
  ))
}

Component:

import { useState } from 'react'
import { useRune } from '@rune-hub/react'
import { todos, addTodo, toggleTodo } from './store'

function TodoList () {
  const todoList = useRune(todos)
  const [text, setText] = useState('')

  const handleSubmit = (e: any) => {
    e.preventDefault()

    if (text.trim()) {
      addTodo(text.trim())
      setText('')
    }
  }

  return (
    <div>
      <form onSubmit={handleSubmit}>
        <input
          value={text}
          onChange={e => setText(e.target.value)}
          placeholder='What needs to be done?'
        />
        <button type='submit'>Add</button>
      </form>
      <ul>
        {todoList.map(({ id, done, text }) => (
          <li
            key={id}
            onClick={() => toggleTodo(id)}
            style={{ textDecoration: done ? 'line-through' : 'none' }}
          >
            {text}
          </li>
        ))}
      </ul>
    </div>
  )
}

API

🏠︎ / API

HubProvideruseRuneuseSlotuseOnuseActionuseHubuseGetSlot

HubProvider

🏠︎ / API / HubProvider

The HubProvider wraps your component tree and makes a Hub instance available to all child components via useHub hook.

import { Hub } from 'rune-hub'
import { HubProvider } from '@rune-hub/react'

const myHub = new Hub()

function App () {
  return (
    <HubProvider value={myHub}>
      <YourComponents />
    </HubProvider>
  )
}

If you don't provide a Hub, the default Hub.root will be used.

useRune

🏠︎ / API / useRune

Subscribes to a Rune and returns its current value.

Uses useSyncExternalStore for proper synchronization with React's rendering cycle. Automatically subscribes to the Rune's slot and unsubscribes on unmount.

import { rune, get } from 'rune-hub'
import { useRune } from '@rune-hub/react'

const count = () => 0
const log = () => console.log(get(count))

function Counter () {
  const value = useRune(count)
  // Subscribe to count changes
  
  useRune(log)
  // Activate log effect

  return <div>Count: {value}</div>
}

useSlot

🏠︎ / API / useSlot

Subscribes to a Slot and returns its current value.

Uses useSyncExternalStore for proper synchronization with React's rendering cycle. Automatically subscribes to the Slot and unsubscribes on unmount.

import { Slot } from 'rune-hub'
import { useSlot } from '@rune-hub/react'

const count = new Slot(() => 0)
const log = new Slot(() => console.log(count.value))

function Counter () {
  const value = useSlot(count)
  // Subscribe to count changes

  useSlot(log)
  // Activate log effect

  return <div>Count: {value}</div>
}

useOn

🏠︎ / API / useOn

Use useOn when you need to run side effects (like logging, analytics, or synchronization) that depend on other Runes, but don't need the return value in your component.

import { rune, get } from 'rune-hub'
import { useRune, useOn } from '@rune-hub/react'

const count = () => 0
const log = () => console.log(get(count))

function Counter () {
  const value = useRune(count)
  // Subscribe to count changes

  useOn(log)
  // Activate log effect

  return <div>Count: {value}</div>
}

useAction

🏠︎ / API / useAction

The hook automatically binds your action to context Hub.

import { slot } from 'rune-hub'
import { useRune, useAction } from '@rune-hub/react'

const count = () => 0
const increment = () => slot(count).value++
const decrement = () => slot(count).value--

function Counter () {
  const value = useRune(count)
  const inc = useAction(increment)
  const dec = useAction(decrement)

  return (
    <div>
      <button onClick={dec}>-</button>
      <span>{value}</span>
      <button onClick={inc}>+</button>
    </div>
  )
}

useHub

🏠︎ / API / useHub

Returns the current Hub instance from context.

import { useHub } from '@rune-hub/react'

function MyComponent () {
  const hub = useHub()

  console.log(hub)

  return <h1>Hello World!</h1>
}

useGetSlot

🏠︎ / API / useGetSlot

Returns a Slot instance for a given Rune within the current Hub context.

A Slot is a Hub-scoped reactive container that tracks changes to a Rune. Use this when you need direct access to the Slot API rather than just the value.

import { useEffect } from 'react'
import { useGetSlot } from '@rune-hub/react'

const count = () => 0

function Counter () {
  const slot = useGetSlot(count)

  useEffect(() => {
    // Access raw value without subscribing
    console.log(slot.raw)

    // Manually listen to changes
    return slot.on('change', () => {
      console.log('Count changed:', slot.raw)
    })
  }, [slot])

  return <div>Count: {slot.raw}</div>
}

The Slot instance is memoized and stable for the Rune and Hub combination.

Links

🏠︎ / Links

Contributions are welcome! Please feel free to submit issues and pull requests.

issues pulls