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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@empellio/react-socket

v0.0.1

Published

Type-safe React hooks & provider for Socket.IO with auto-reconnect, auth token refresh, room helpers, optimistic updates, and RPC (ack) requests. React 18+.

Readme

@empellio/react-socket

Type-safe React hooks & provider for Socket.IO with auto-reconnect, auth token refresh, room helpers, optimistic updates, and RPC (ack) requests. React 18+.

Installation

npm install @empellio/react-socket socket.io-client

Quick start (typed)

// types.ts
import { createSocketTypes } from '@empellio/react-socket'

type ServerToClient = {
  'room:message': { roomId: string; message: string; userId: string; ts: number }
}
type ClientToServer = {
  'room:send': { roomId: string; message: string }
}

export const api = createSocketTypes<ServerToClient, ClientToServer>()
// App.tsx
import { api } from './types'
const { SocketProvider } = api

export function App() {
  return (
    <SocketProvider url={import.meta.env.VITE_SOCKET_URL} namespace="/chat">
      <YourApp />
    </SocketProvider>
  )
}

More docs coming soon.

API Reference

  • SocketProvider(props)
    • url, namespace, autoConnect, getToken, auth, transports, reconnection, reconnectionAttempts, reconnectionDelay, reconnectionDelayMax, timeout, query, onConnectError, onAuthError
  • SocketBoundary({ children, fallback })
  • useSocket() → { socket, connected, connecting, error, latencyMs, attempts, lastError, reconnectIn }
  • useSocketEvent(event, handler, deps?)
  • useEmit(event) → { emit, emitAck, loading, error }
  • useRequest(event, { timeout? }) → { call, loading, error }
  • useRoom(roomId, { autoJoin?, deps? }) → { join, leave, inRoom }
  • usePresence() → { users, lastUpdate }
  • useOptimistic(selector) → (event, optimisticUpdate, rollback?) → { emit }
  • useConnection() → { connected, connecting, attempts, lastError, reconnectIn }
  • useLatency(intervalMs?) → { latencyMs }
  • useSubchannel(event, key, handler, deps?)
  • SocketDevtools overlay (enable with localStorage.setItem('empellio:debug','react-socket:*'))

Auth & Token refresh

  • On connect, if getToken is provided, its result is added to auth.token.
  • On connect_error with 401/invalid token, the provider retries by calling getToken() again and reconnects. onAuthError is called if refresh fails.

Reconnect/backoff metadata

  • useConnection() exposes attempts, lastError, and reconnectIn (estimated ms until next try based on backoff config).

Offline queue & auto rejoin

  • Emits while offline are queued up to 30s and replayed on reconnect.
  • Joined rooms are remembered and rejoined automatically after reconnect.

Rooms & Presence

  • useRoom(roomId) emits room:join/room:leave with ack callbacks and tracks membership.
  • usePresence() listens to presence:update conventionally and keeps users and lastUpdate.

RPC / Ack

  • useEmit(event).emitAck(payload, { timeout, signal }) returns the ack result or throws on timeout/abort.
  • useRequest(event) is a convenience wrapper with loading/error state.

Optimistic UI

const [list, setList] = useState<string[]>([])
const optimistic = useOptimistic(() => [list, setList])
const { emit } = optimistic('room:send', ({ message }) => [...list, message])

SSR notes

  • Provider defers socket creation until effects run (no window access on server). Hooks are no-ops on server.