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

@inno-isw/sse-hooks

v1.0.0

Published

TanStack-like React hooks for Server-Sent Events (SSE)

Readme

@inno-isw/sse-hooks

TanStack-like React hooks for Server-Sent Events (SSE). Makes real-time streaming as easy as REST.

Installation

npm install @inno-isw/sse-hooks
# or
pnpm add @inno-isw/sse-hooks

Quick Start

import { SSEProvider, createSSEClient, useSSE } from '@inno-isw/sse-hooks';

// 1. Create a client (like QueryClient)
const sseClient = createSSEClient({
  baseURL: 'https://api.example.com',
  headers: () => ({
    Authorization: `Bearer ${getToken()}`,
  }),
});

// 2. Wrap your app (like QueryClientProvider)
function App() {
  return (
    <SSEProvider client={sseClient}>
      <MeterStatus />
    </SSEProvider>
  );
}

// 3. Use the hook (like useQuery)
function MeterStatus() {
  const { data, isConnected, error } = useSSE<MeterData>({
    url: '/api/v1/meters/stream',
    params: { groupId: '42' },
    enabled: !!groupId,
  });

  if (error) return <div>Error: {error.message}</div>;
  if (!isConnected) return <div>Connecting...</div>;

  return <div>Meters Online: {data?.onlineCount}</div>;
}

API Reference

createSSEClient(config)

Creates a configured SSE client.

const client = createSSEClient({
  baseURL: 'https://api.example.com',    // Base URL for all requests
  headers: { 'X-API-Key': 'key' },       // Static headers
  // or dynamic headers:
  headers: () => ({ Authorization: getToken() }),
  reconnect: true,                        // Enable auto-reconnect (default: true)
  reconnectInterval: 1000,                // Base reconnect interval in ms (default: 1000)
  maxReconnectAttempts: 10,               // Max retry attempts (default: 10)
  withCredentials: false,                 // Include cookies (default: false)
});

useSSE<T>(options)

Main hook for SSE connections.

const {
  data,           // Latest data received (T | null)
  status,         // 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'error'
  error,          // Error object if status is 'error'
  isConnected,    // true when status === 'connected'
  isConnecting,   // true when status === 'connecting'
  isReconnecting, // true when status === 'reconnecting'
  isError,        // true when status === 'error'
  isIdle,         // true when status === 'idle'
  reconnectCount, // Number of reconnection attempts
  disconnect,     // Function to manually disconnect
  reconnect,      // Function to manually reconnect
} = useSSE<MeterData>({
  url: '/stream',                        // Endpoint path (required)
  params: { id: '123' },                 // Query parameters
  enabled: true,                         // Enable/disable connection (default: true)
  eventName: 'update',                   // Filter by SSE event name
  headers: { 'X-Custom': 'value' },      // Additional headers for this connection
  onMessage: (data) => {},               // Callback on each message
  onError: (error) => {},                // Callback on error
  onOpen: () => {},                      // Callback on connection open
  onClose: () => {},                     // Callback on connection close
  select: (raw) => raw.transformed,      // Transform incoming data
  reconnect: true,                       // Override client reconnect setting
  reconnectInterval: 2000,               // Override client interval
  maxReconnectAttempts: 5,               // Override client max attempts
});

SSEProvider

Context provider for SSEClient.

<SSEProvider client={sseClient}>
  {children}
</SSEProvider>

useSSEClient()

Access the SSE client from context.

const client = useSSEClient();
const url = client.buildURL('/stream', { id: '123' });

Without Provider

You can use useSSE without a provider by passing full URLs:

const { data } = useSSE({
  url: 'https://api.example.com/stream',
  headers: { Authorization: 'Bearer token' },
});

Features

  • TypeScript-first: Full type safety with generics
  • Auto-reconnect: Exponential backoff with jitter
  • Dynamic headers: Support for auth token refresh
  • Event filtering: Subscribe to specific SSE event names
  • Data transformation: select function like TanStack Query
  • Manual control: disconnect() and reconnect() functions
  • Lightweight: ~3KB gzipped

License

MIT