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

@recached/react

v0.1.5

Published

Official React hooks for Recached — zero-latency reactive cache

Readme

@recached/react

Official React hooks for Recached — zero-latency reactive cache with automatic server sync and cross-tab sharing.

Features

  • Zero-latency reads — all reads are served from local WASM memory, no network round-trip
  • Automatic re-renders — components update when a key changes from any source: local writes, server WebSocket push, or BroadcastChannel cross-tab sync
  • React 18 concurrent-safe — built on useSyncExternalStore, no tearing
  • TypeScript-first — full type inference including useKeyJSON<T>

Requirements

  • React 18 or later
  • recached-edge 0.1.4 or later (peer dependency)

Installation

npm install @recached/react recached-edge

Quick start

Mount <RecachedProvider> once near the root of your app, then use useKey anywhere inside it.

import { RecachedProvider, useKey, useRecached } from '@recached/react';

function App() {
  return (
    <RecachedProvider
      options={{
        persistence: true,
        connect: { url: 'ws://localhost:6380' },
      }}
    >
      <Counter />
    </RecachedProvider>
  );
}

function Counter() {
  const cache = useRecached();
  const count = useKey('count');

  return (
    <button onClick={() => cache.set('count', String(Number(count ?? 0) + 1))}>
      Count: {count ?? 0}
    </button>
  );
}

Clicking the button updates count in the WASM store, notifies all useKey('count') subscribers in the same tab, syncs to the server, and fans out to all other connected tabs and clients — all without a page reload.

API

<RecachedProvider>

<RecachedProvider options={CacheOptions}>
  {children}
</RecachedProvider>

Creates and provides a Cache instance to all descendants. Renders null until the cache is ready (WASM init + optional persistence hydration).

| Prop | Type | Description | |------|------|-------------| | options | CacheOptions | Passed to createCache. Controls persistence, BroadcastChannel, and server connection. | | cache | Cache | Pass a pre-built Cache instance instead of creating one. When set, options is ignored. |

// With server connection
<RecachedProvider options={{ connect: { url: 'ws://localhost:6380', password: 'secret' } }}>

// With persistence (survives page refresh)
<RecachedProvider options={{ persistence: true }}>

// Cross-tab sync only (no server)
<RecachedProvider options={{ broadcastChannel: 'my-app' }}>

// Pre-built instance (advanced)
const cache = await createCache({ ... });
<RecachedProvider cache={cache}>

useRecached()

function useRecached(): Cache

Returns the Cache instance from the nearest <RecachedProvider>. Use this to call set, setEx, setJSON, del, publish, and other write or imperative methods.

Throws if called outside a <RecachedProvider>.

function SaveButton() {
  const cache = useRecached();
  return (
    <button onClick={() => cache.setJSON('user', { id: 1, name: 'Alice' }, 300)}>
      Save
    </button>
  );
}

useKey(key)

function useKey(key: string): string | null

Reactively reads a string value. Returns null when the key does not exist or has expired. Re-renders the component automatically whenever the key changes — from any mutation source.

const theme = useKey('theme'); // "dark" | "light" | null

useKeyJSON<T>(key)

function useKeyJSON<T>(key: string): T | null

Same as useKey but JSON-parses the value. Returns null on a missing key, expired key, or invalid JSON.

interface User { id: number; name: string }

function UserCard() {
  const user = useKeyJSON<User>('user:42');
  if (!user) return <Spinner />;
  return <p>{user.name}</p>;
}

Reactivity model

Every write — whether it comes from the same component, another component in the same tab, another tab via BroadcastChannel, or another client via the server — fires the mutation bus, which causes all useKey / useKeyJSON subscribers to re-read their key and re-render if the value changed.

Local write (cache.set)
  └─▶ WASM store update
  └─▶ notify_mutation → re-render all useKey subscribers
  └─▶ WebSocket send → server fan-out → other clients
  └─▶ BroadcastChannel post → other tabs
        └─▶ WASM store update → notify_mutation → re-render

Examples

Theme toggle

function ThemeToggle() {
  const cache = useRecached();
  const theme = useKey('theme') ?? 'light';
  return (
    <button onClick={() => cache.set('theme', theme === 'light' ? 'dark' : 'light')}>
      {theme === 'light' ? '🌙 Dark mode' : '☀️ Light mode'}
    </button>
  );
}

Shared shopping cart

interface CartItem { id: string; qty: number }

function Cart() {
  const cache = useRecached();
  const items = useKeyJSON<CartItem[]>('cart') ?? [];

  function addItem(id: string) {
    const updated = [...items, { id, qty: 1 }];
    cache.setJSON('cart', updated, 3600);
  }

  return (
    <ul>
      {items.map((item) => <li key={item.id}>{item.id} × {item.qty}</li>)}
    </ul>
  );
}

With expiry

function SessionBanner() {
  const cache = useRecached();
  const session = useKey('session');

  if (!session) return <LoginPrompt />;
  return <p>Logged in — session expires soon</p>;
}

// Elsewhere: set with 30-minute TTL
cache.setEx('session', userId, 1800);

License

MIT