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

@crimson_dev/use-resize-observer

v1.0.0

Published

Zero-dependency, Worker-native, ESNext-first React 19 ResizeObserver hook

Downloads

700

Readme

Zero-dependency, Worker-native, ESNext-first React 19 ResizeObserver hook


Quick Start

npm install @crimson_dev/use-resize-observer
import { useResizeObserver } from '@crimson_dev/use-resize-observer';

function ResponsiveCard() {
  const { ref, width, height } = useResizeObserver<HTMLDivElement>();

  return (
    <div ref={ref}>
      {width} × {height}
    </div>
  );
}

Why This Exists

Most resize hooks create one ResizeObserver per component. At scale, that means hundreds of observers competing for the main thread. This library uses a shared observer pool — one ResizeObserver per document root — with requestAnimationFrame batching and React startTransition wrapping. The result: 100 elements resizing = 1 render cycle.

Highlights

Entry Points

// Main — primary hook
import { useResizeObserver } from '@crimson_dev/use-resize-observer';

// Multi-element — observe N elements with 1 hook
import { useResizeObserverEntries } from '@crimson_dev/use-resize-observer';

// Factory — framework-agnostic, imperative API
import { createResizeObserver } from '@crimson_dev/use-resize-observer';

// Worker — SAB-based measurements for cross-thread sharing
import { useResizeObserverWorker } from '@crimson_dev/use-resize-observer/worker';

// Core — EventTarget-based, any framework
import { createResizeObservable } from '@crimson_dev/use-resize-observer/core';

// Server — SSR/RSC safe
import { createServerResizeObserverMock } from '@crimson_dev/use-resize-observer/server';

// Shim — polyfill for legacy browsers
import '@crimson_dev/use-resize-observer/shim';

API

useResizeObserver<T>(options?)

const { ref, width, height, entry } = useResizeObserver<HTMLDivElement>({
  box: 'content-box',        // 'content-box' | 'border-box' | 'device-pixel-content-box'
  ref: externalRef,           // optional external ref
  root: shadowRoot,           // optional Document | ShadowRoot
  onResize: (entry) => {},    // stable callback (no useCallback needed)
});

| Return | Type | Description | |--------|------|-------------| | ref | RefObject<T \| null> | Attach to the element to observe | | width | number \| undefined | Inline size of the observed box | | height | number \| undefined | Block size of the observed box | | entry | ResizeObserverEntry \| undefined | Raw entry from the observer |

useResizeObserverEntries(refs, options?)

const entries = useResizeObserverEntries([ref1, ref2, ref3], {
  box: 'border-box',
});
// entries: Map<Element, { width, height, entry }>

createResizeObserver(options?)

using observer = createResizeObserver({ box: 'border-box' });
observer.observe(element, (entry) => console.log(entry));
// Automatically cleaned up via Symbol.dispose

Architecture

┌─────────────────────────────────────────────────┐
│                  Your Components                 │
│  useResizeObserver()  useResizeObserverEntries() │
└──────────────────────┬──────────────────────────┘
                       │
              ┌────────▼────────┐
              │   ObserverPool  │  1 per document root
              │ WeakMap<Element,│  Single-callback fast path
              │ Callback|Set>   │  FinalizationRegistry
              └────────┬────────┘
                       │
              ┌────────▼────────┐
              │  RafScheduler   │  Double-buffered Maps
              │  XOR swap       │  Zero-alloc flush
              │  last-write-wins│  requestAnimationFrame
              └────────┬────────┘
                       │
              ┌────────▼────────┐
              │ startTransition │  Non-urgent batched update
              │   setState()    │  1 render per frame
              └─────────────────┘

Comparison

| | use-resize-observer@9 | @crimson_dev/use-resize-observer | |---|---|---| | Bundle | ~800B | 1.11 kB (pool + scheduler + hook) | | React | 16.8+ | 19.3+ with Compiler | | Module | CJS + ESM | ESM only | | TypeScript | 4.x | 6.0 strict | | Observer model | 1 per component | Shared pool | | Worker mode | — | SharedArrayBuffer | | Box models | content-box only | All 3 | | GC cleanup | Manual | Automatic | | Batching | None | rAF + startTransition |

Requirements

  • Node ≥ 25.0.0
  • React ≥ 19.3.0
  • TypeScript ≥ 6.0 (recommended)
  • Browser with native ResizeObserver (or use the /shim entry)

License

MIT — Crimson Dev