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

@canonical/react-head

v0.30.0

Published

Declarative head management for React with SSR collection

Readme

@canonical/react-head

Declarative head management for React. Components declare <title>, <meta>, and <link> tags via useHead(). Tags mount with the component, update on change, and are removed on unmount. SSR collection via createHeadCollector() captures tags during server rendering for injection into the HTML template.

No dependency on the router — works with any React app.

Installation

bun add @canonical/react-head

Requires react as a peer dependency.

Quick start

Client

import { HeadProvider, useHead } from "@canonical/react-head";

function App() {
  return (
    <HeadProvider>
      <Shell>
        <Page />
      </Shell>
    </HeadProvider>
  );
}

function Shell({ children }) {
  useHead({ title: "My App" });
  return <main>{children}</main>;
}

function Page() {
  useHead({
    title: "User Profile — My App",
    meta: [
      { name: "description", content: "User profile page" },
      { property: "og:image", content: "/images/profile.png" },
    ],
    link: [
      { rel: "canonical", href: "https://example.com/profile" },
    ],
  });

  return <h1>Profile</h1>;
}

On the client, useHead() performs direct DOM mutations on document.head. Tags are scoped to the component — navigating away removes the route's tags, the shell's tags remain (because the shell never unmounts).

Server (SSR)

import { createHeadCollector, HeadProvider } from "@canonical/react-head";
import { renderToPipeableStream } from "react-dom/server";

const headCollector = createHeadCollector();

const { pipe } = renderToPipeableStream(
  <HeadProvider collector={headCollector}>
    <App />
  </HeadProvider>,
  {
    onShellReady() {
      const headHtml = headCollector.toHtml();
      res.write(`<!doctype html><html><head>${headHtml}</head><body>`);
      pipe(res);
    },
  },
);

During SSR, useHead() writes to the collector instead of the DOM. After the shell renders (onShellReady), call toHtml() to serialize the collected tags. Shell-level tags (base title, viewport meta) are available immediately. Route-specific tags from suspended components are applied during client-side hydration.

Tag merging

When multiple components call useHead(), the following rules apply:

  • title — last writer wins. The deepest component in the tree takes priority.
  • meta by name or property — deduplicated by key. The deepest component's value wins.
  • link — accumulated. All link tags from all components are rendered.

This means the shell can set a base title and description, and each route overrides them with page-specific values.

Public API

  • HeadProvider — React context provider. On the server, pass a collector. On the client, omit it.
  • useHead(tags) — declare head tags from any component.
  • createHeadCollector() — create an SSR collector with add(), remove(), and toHtml().
  • HeadTags — type for { title?, meta?, link? }.
  • HeadMeta — type for meta tag attributes.
  • HeadLink — type for link tag attributes.
  • HeadCollector — type for the SSR collector interface.