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

@typefit/react

v1.0.0

Published

React APIs to make text always fit perfectly.

Readme

@typefit/react

React bindings for Typefit.

Install this package in React apps. It includes a small polymorphic component, a hook, and all public Typefit types re-exported from @typefit/core.

Install

bun add @typefit/react
npm install @typefit/react

@typefit/react depends on @typefit/core, so you won't need to install the core package separately.

Component

import { Typefit } from '@typefit/react';

export function Hero() {
  return (
    <Typefit as="h1" maxSize={96} lines={{ min: 2 }} hideUntilFit>
      Text that always fits perfectly.
    </Typefit>
  );
}

Typefit is polymorphic through the as prop and forwards regular element props such as className, style, id, and event handlers.

<Typefit
  as="h2"
  className="font-semibold tracking-tight text-neutral-950"
  maxSize={80}
  lines={{ target: 2, max: 3 }}
>
  Styled with normal React props.
</Typefit>

Hook

Use useTypefit when you need direct access to the result or a manual refresh.

import { useTypefit } from '@typefit/react';

export function MeasuredHeadline() {
  const { ref, result, refresh } = useTypefit<HTMLHeadingElement>({
    maxSize: 96,
    lines: { target: 2 },
  });

  return (
    <>
      <h1 ref={ref}>Measured with a hook.</h1>
      <button type="button" onClick={refresh}>
        Refresh
      </button>
      <output>{result?.fontSize.toFixed(1)}px</output>
    </>
  );
}

Custom Fonts

Use CSS normally:

@font-face {
  font-family: "Open Runde";
  src: url("/fonts/OpenRunde-Semibold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

.headline {
  font-family: "Open Runde", system-ui, sans-serif;
  font-weight: 600;
  line-height: 1.05;
}
<Typefit as="h1" className="headline" hideUntilFit>
  Custom font from CSS.
</Typefit>

For stricter measurement control, pass a font callback:

const headlineFont = (size: number) =>
  `600 ${size}px "Open Runde", system-ui, -apple-system, sans-serif`;

<Typefit as="h1" font={headlineFont} maxSize={112}>
  Explicit custom font.
</Typefit>;

Typefit listens for browser font-loading events, clears cached metrics, and refits observed instances after the real font is ready.

Common Props

| Prop | Default | Description | | --- | --- | --- | | as | 'span' | Element rendered by the component. | | hideUntilFit | false | Hide until the first measurement completes. | | disabled | false | Skip fitting. | | onFit | none | Called with (result, element) after fitting. | | minSize | 10 | Smallest font size Typefit may choose. | | maxSize | 512 | Largest font size Typefit may choose. | | lines | none | { min, target, max } line-count policy. | | strategy | 'balance' | 'balance' or 'fill'. | | balance | { mode: 'even' } | Wrap scoring options. | | shape | none | Shape preset or custom rows. | | snap | none | Allowed font sizes. | | avoidWidows | false | Avoid short final lines when possible. | | observe | true | Refit on resize, content changes, and font loads. |

All core fitting options are supported.

Shape Example

<Typefit
  as="h1"
  maxSize={96}
  lines={{ min: 3 }}
  shape="diamond"
  balance={{ mode: 'even' }}
>
  Widest in the middle.
</Typefit>

Snap Example

<Typefit snap={[24, 32, 40, 48, 56, 64, 72, 88, 104, 120]}>
  Fit to a type scale.
</Typefit>

Browser Support

@typefit/react works in any current browser supported by React and Typefit. The underlying @typefit/core measurement uses OffscreenCanvas when available and falls back to a DOM canvas context, so Chromium, Firefox, WebKit/Safari, and other standards-compliant browsers are supported.

The component and hook also listen for resize, mutation, and browser font-loading events when observe is enabled.

Contributing

We would love to have your help in making Typefit better.

Here's how you can contribute:

License

Typefit is licensed under the MIT License.