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

@channel-state/react

v0.0.5

Published

React hooks for channel-state, providing seamless integration with React applications for cross-context state management.

Downloads

15

Readme

📖 Overview

@channel-state/react provides a set of idiomatic React hooks for integrating channel-state into your React applications. It uses the useSyncExternalStore hook to ensure efficient, concurrent-safe updates, making it easy to build responsive and synchronized user interfaces.

🛠️ Installation

npm install @channel-state/core @channel-state/react
yarn add @channel-state/core @channel-state/react
pnpm add @channel-state/core @channel-state/react
bun add @channel-state/core @channel-state/react

🌐 CDN Usage

For direct usage in the browser, you can use the UMD builds from a CDN like jsDelivr or unpkg. Note that you must also include the react, react-dom, and @channel-state/core packages.

<script src="https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@channel-state/core@0"></script>
<script src="https://cdn.jsdelivr.net/npm/@channel-state/react@0"></script>

🚀 Playground

Explore and experiment with @channel-state/react in a live environment using our interactive playground.

This playground provides a simple example of how to use @channel-state/core and @channel-state/react together.

Note: To see the cross-tab state synchronization in action, open the preview in a new tab.

📚 API Reference

useChannelState<T>

A hook for accessing and updating a ChannelStore's state.

| Parameter | Type | Description | | --------- | ----------------- | ------------------------------------------ | | store | ChannelStore<T> | The ChannelStore instance to connect to. |

| Returns | Type | Description | | ---------- | ----------------------- | ----------------------------------------------------------------------------------------------- | | state | T | The current state of the store. | | setState | (newValue: T) => void | A function to update the state of the store. This is a wrapper around the store's set method. |

useChannelStatus<T>

A hook for accessing the status of a ChannelStore.

| Parameter | Type | Description | | --------- | ----------------- | ------------------------------------------ | | store | ChannelStore<T> | The ChannelStore instance to connect to. |

| Returns | Type | Description | | -------- | ------------- | ------------------------------------------------------------------------------- | | status | StoreStatus | The current status of the store: 'initializing', 'ready', or 'destroyed'. |

🚀 Example Usage

First, create a ChannelStore instance and export it. This should be done in a separate file to be shared across your components.

// src/store.ts
import { ChannelStore } from '@channel-state/core'

export const counterStore = new ChannelStore<number>({
  name: 'shared-counter',
  initial: 0,
  persist: true,
})

Now, you can use the hooks in your React components:

// src/components/Counter.tsx
import React, { useEffect } from 'react'
import { useChannelState, useChannelStatus } from '@channel-state/react'
import { counterStore } from '../store'

function Counter() {
  // useChannelState provides the current state and a setter function.
  const [count, setCount] = useChannelState(counterStore)
  // useChannelStatus provides the current status of the store.
  const status = useChannelStatus(counterStore)

  // It's good practice to handle the initializing state,
  // especially when persistence is enabled.
  if (status !== 'ready') {
    return <div>Loading state...</div>
  }

  return (
    <div>
      <h2>Counter</h2>
      <p>Current count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      <button onClick={() => setCount(count - 1)}>Decrement</button>
      {/* You can still call store methods directly */}
      <button onClick={() => counterStore.reset()}>Reset to Initial</button>
    </div>
  )
}

export default Counter