Skip to content
A small library for continuous things.WebSockets / React / SSE

@ibnlanre/socket

Stay
connected.

Live data has a life of its own.
Give it a place in your React app.

A type-safe WebSocket and Server-Sent Events client with shared connections, cached state, and a way back when the network drops.

Start building Meet Socket
One stream. Many places to belong.An endpoint connects to a shared Socket, which distributes messages to three React components.ENDPOINTsocketONE SHARED CONNECTIONCOMPONENT 01COMPONENT 02COMPONENT 03
One stream.
Many places to belong.
S
↳
Make the connectionpnpm add @ibnlanre/socket

01 / The essentials

Less plumbing.
More possibility.

The connection is only the beginning.
Socket takes care of what comes after.

02 / In practice

One client.
Your whole app.

Define an endpoint. Subscribe in a component.
Let the messages come to you.

Walk through the setup
price-ticker.tsxREACT + TYPESCRIPT
// A client lives outside your components.
import { SocketClient } from "@ibnlanre/socket";

const prices = new SocketClient<string>({
  baseURL: "wss://example.com",
  url: "/prices",
  retry: true,
});

// Each component gets a reactive snapshot.
export function PriceTicker() {
  const { data } = prices.useSocket();
  return <p>{data ?? "Waiting for price…"}</p>;
}
Shared connection. Individual perspective.

The manual is open.

Find your
starting point.
Explore the guide, or go straight to the details.API reference ↗

Released under the BSD-3-Clause License.