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

@nicolaferraro/realtime-sdk-react

v0.1.0

Published

React hooks for Redpanda Realtime SDK

Readme

Redpanda Realtime SDK - React

React hooks for Redpanda Realtime SDK.

Installation

npm install @nicolaferraro/realtime-sdk-react

Usage

Basic Example (Default Reducer)

The default reducer accumulates data into an array:

import { useChannel } from '@nicolaferraro/realtime-sdk-react';

interface ChatMessage {
  text: string;
  username: string;
}

function ChatRoom() {
  const { subChannel: messages, pubChannel } = useChannel<ChatMessage>('chat-room');

  const sendMessage = async () => {
    await pubChannel({ text: 'Hello!', username: 'Alice' });
  };

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i}>
          {msg.username}: {msg.text}
        </div>
      ))}
      <button onClick={sendMessage}>Send</button>
    </div>
  );
}

Custom Reducer

Use a custom reducer to manage state differently:

function Counter() {
  const { subChannel: count, pubChannel } = useChannel<number, number>(
    'counter',
    [
      0,                           // Initial state
      (state, value) => state + value  // Reducer function
    ]
  );

  return (
    <div>
      <div>Count: {count}</div>
      <button onClick={() => pubChannel(1)}>+1</button>
    </div>
  );
}

With Error Handling

function MyComponent() {
  const { subChannel, pubChannel, error } = useChannel<Message>('my-channel');

  return (
    <div>
      {error && <div>Error: {error.message}</div>}
      {/* ... */}
    </div>
  );
}

With Custom Client

import { Redpanda } from '@nicolaferraro/realtime-sdk';

const client = new Redpanda('https://api.example.com');

function MyComponent() {
  const { subChannel, pubChannel } = useChannel(
    'my-channel',
    undefined, // Use default reducer
    {
      client,
      onError: (err) => console.error(err),
    }
  );

  // ...
}

API

useChannel<T, S>(channelName, reducer?, options?)

React hook for interacting with a channel with reducer pattern.

Parameters

  • channelName: string - The name of the channel
  • reducer?: [S, (state: S, data: T) => S] - Optional reducer tuple (defaults to array accumulation)
  • options?: UseChannelOptions - Configuration options

Reducer

The reducer is a tuple of [initialState, reducerFunction]:

[
  initialState,          // Initial value
  (state, data) => newState  // Reducer function
]

The reducer function receives:

  • state: S - The current state
  • data: T - The received data payload (not including the key)

Default Reducer: If no reducer is provided, data is accumulated into an array T[].

Options

interface UseChannelOptions {
  client?: Redpanda;                // Custom client instance
  onError?: (error: Error) => void; // Error handler
}

To configure the base URL, create a custom Redpanda client:

const client = new Redpanda('https://api.example.com');
const { subChannel, pubChannel } = useChannel('channel', undefined, { client });

Returns

{
  subChannel: S;                           // Accumulated state
  pubChannel: (data: T) => Promise<void>;  // Publish function
  error?: Error | null;                    // Last error (optional)
}

You can destructure only what you need:

// Just the data
const { subChannel, pubChannel } = useChannel('channel');

// Include error handling
const { subChannel, pubChannel, error } = useChannel('channel');

Features

  • Reducer pattern for flexible state management
  • Default array accumulation (no reducer needed)
  • Keys handled automatically by the SDK (empty string used for publish)
  • Automatic connection management
  • Automatic reconnection with exponential backoff
  • Stream resumption from last received key
  • TypeScript support with generics
  • React lifecycle integration (cleanup on unmount)
  • Error handling with optional error callback