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

@socketly/react

v0.1.1

Published

React hooks for Socketly — useChannel, usePresence, and a provider that survives reconnects.

Readme

@socketly/react

React hooks for Socketly — realtime channels and presence, with the reconnect handling already done.

npm install @socketly/client @socketly/react

Provider

Create the client once, outside your components, so a re-render never opens a second connection.

// lib/socketly.ts
import { Socketly } from '@socketly/client';

export const socketly = new Socketly({
  key: process.env.NEXT_PUBLIC_SOCKETLY_KEY!,
  authEndpoint: '/api/socketly/auth', // needed for private-/presence-
});
// app/providers.tsx
'use client';

import { SocketlyProvider } from '@socketly/react';
import { socketly } from '@/lib/socketly';

export function Providers({ children }: { children: React.ReactNode }) {
  return <SocketlyProvider client={socketly}>{children}</SocketlyProvider>;
}

useChannel

'use client';

import { useState } from 'react';
import { useChannel } from '@socketly/react';

export function Notifications({ userId }: { userId: string }) {
  const [items, setItems] = useState<Notification[]>([]);

  const { subscribed, error } = useChannel(`private-user-${userId}`, {
    notification: ({ data }) => setItems((prev) => [data, ...prev]),
  });

  if (error) return <p>{error}</p>;
  if (!subscribed) return <p>Connecting…</p>;

  return <List items={items} />;
}

Handlers are read through a ref, so an inline arrow function does not resubscribe on every render. Only the set of event names drives resubscription. This is the failure the previous integration guide shipped: an object literal in a dependency array produced a reconnect loop that looked like a flaky network.

Pass null as the channel name to subscribe to nothing — useful while an id is still loading:

useChannel(roomId ? `presence-room-${roomId}` : null, handlers);

usePresence

const { members, count } = usePresence(`presence-room-${roomId}`);

return (
  <>
    <p>{count} online</p>
    {members.map((m) => <Avatar key={m.userId} name={m.userInfo?.name} />)}
  </>
);

The roster stays in sync as people join and leave. Identities come from inside the payload your server signed, so nobody can appear as someone else.

useConnectionState

const state = useConnectionState();
// 'initialized' | 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'failed'

Backed by useSyncExternalStore, so it is safe with concurrent rendering and server rendering.

Sending

useChannel returns a trigger for client events — browser-to-browser, for things like typing indicators. They must be enabled on the app, only work on private-/presence- channels, and their names must start with client-.

const { trigger } = useChannel(channel, handlers);
trigger('client-typing', { userId });

Anything that should be trusted goes through your backend with @socketly/server instead.

Server components

Every hook here is client-side; the entry point is marked 'use client'. Import them from a component that is too.

Full documentation: docs.socketly.co

MIT