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

@htmdjs/react

v0.1.0-alpha.5

Published

React adapter for .htmd — static <HtmdDoc/> and streaming useHtmdStream() hook

Readme

@htmdjs/react

React adapter for HTMD. Requires React 18 or newer.

import { baseCatalog, createHost } from '@htmdjs/contracts';
import { HtmdDoc, useHtmdStream } from '@htmdjs/react';
import { streamText } from '@htmdjs/wire';
import { useMemo } from 'react';

// Module scope keeps the host identity stable.
const host = createHost({ components: baseCatalog.without('data-table') });

export function Message() {
  return <HtmdDoc source={'# Hello\n\nStreaming-first Markdown.'} host={host} />;
}

// Stream model output (any AsyncIterable<string>) straight into the page.
export function Live({ tokens }: { tokens: AsyncIterable<string> }) {
  const source = useMemo(() => streamText(tokens), [tokens]);
  const { ref, status, error } = useHtmdStream(source, { host, limits: { maxRegions: 200 } });
  return <section><div ref={ref} /><p>{status}{error ? `: ${error}` : ''}</p></section>;
}

HtmdDoc accepts source, optional host, and optional onDiagnostics(diagnostics: ReadonlyArray<HtmdDiagnostic>), which receives parser and contract diagnostics. useHtmdStream(source, options?) accepts { host?, limits? } (Partial<RenderLimits> from @htmdjs/renderer). Without a host, defaultHost from @htmdjs/contracts applies. Both entry points register the built-in custom elements on mount; only components in the host catalog render.

HtmdDoc server-renders and hydrates. On the server (react-dom/server) it emits the document as HTML via renderHtmdToString from @htmdjs/renderer: Markdown plus component tags with validated attributes. hydrateRoot adopts that markup without hydration errors; after mount the component registers the elements and re-materializes the same content in place, so components upgrade, load their data, and become interactive on the client. Pass the same source and host on server and client. The container's interior is owned by the renderer, so HtmdDoc does not accept children or dangerouslySetInnerHTML.

Keep source and host identities stable across renders; memoize streamText(...) so a re-render does not restart the stream. One-shot sources such as streamText work under React StrictMode, and unmounting closes the underlying text source. Accepted stream sources are Iterable<WireEvent>, AsyncIterable<WireEvent>, ReadableStream<WireEvent>, and EventSource. Fetch byte streams require decoding/framing first. SSE messages carry one JSON-encoded wire event each.

  • idle: no event has arrived; an empty finite source remains idle.
  • streaming: events are being consumed.
  • done: the renderer accepted doc-done, including on an SSE connection that remains open.
  • error: transport failure, fatal renderer error (including an exceeded render limit), or a nonempty finite source ending without doc-done.

Completion, failure, unmount, and source replacement stop further event application. Owned stream readers are cancelled/released and unfinished async iterators receive return(). SSE listeners are removed, but the hook does not close caller-owned EventSource connections. Source replacement clears prior document/error state. Automatic reconnect and restoration of event history belong to the host application.

Part of HTMD. Install with npm install @htmdjs/react@alpha.