Skip to content
On this page

Performance

For a Hook library, small has two meanings: little code to download and little native work left running in the page.

What the package contains

better-hooks build reportv1.3.0 · build 8f90ccf61cae
Direct entries
37
Median gzip
1.04 kB
Complete root graph
21.2 kB
Within size budget
37 / 37
Largest direct entries by gzipEach row includes the entry and its unique reachable internal modules.
  1. use-websocket3.07 kB
  2. use-key-press2.68 kB
  3. use-session-storage2.17 kB
  4. use-local-storage2.17 kB
  5. use-intersection-observer1.98 kB
  6. use-resize-observer1.74 kB
  7. use-click-outside1.55 kB
  8. use-debounce-fn1.44 kB
View all 37 direct entries
EntryModulesRawgzipBrotligzip / budget
use-async34.37 kB1.33 kB1.13 kBWithin budget: 1.33 kB / 2.05 kB
use-boolean21.55 kB623 B527 BWithin budget: 623 B / 2.05 kB
use-click-outside35.05 kB1.55 kB1.30 kBWithin budget: 1.55 kB / 2.05 kB
use-controllable-state22.59 kB923 B766 BWithin budget: 923 B / 2.05 kB
use-copy-to-clipboard33.37 kB1.24 kB1.04 kBWithin budget: 1.24 kB / 2.05 kB
use-counter22.76 kB1.04 kB873 BWithin budget: 1.04 kB / 2.05 kB
use-debounce23.25 kB996 B856 BWithin budget: 996 B / 2.05 kB
use-debounce-fn44.59 kB1.44 kB1.26 kBWithin budget: 1.44 kB / 2.05 kB
use-document-visibility13.94 kB1.14 kB984 BWithin budget: 1.14 kB / 2.05 kB
use-event-listener34.05 kB1.19 kB1.03 kBWithin budget: 1.19 kB / 2.05 kB
use-hover35.07 kB1.39 kB1.19 kBWithin budget: 1.39 kB / 2.05 kB
use-input22.76 kB1.03 kB833 BWithin budget: 1.03 kB / 2.05 kB
use-intersection-observer37.34 kB1.98 kB1.71 kBWithin budget: 1.98 kB / 2.05 kB
use-interval42.14 kB839 B708 BWithin budget: 839 B / 2.05 kB
use-is-mounted21.27 kB565 B431 BWithin budget: 565 B / 2.05 kB
use-isomorphic-layout-effect1491 B302 B235 BWithin budget: 302 B / 2.05 kB
use-key-press38.59 kB2.68 kB2.33 kBWithin budget: 2.68 kB / 3.07 kB
use-latest21.27 kB585 B451 BWithin budget: 585 B / 2.05 kB
use-local-storage28.60 kB2.17 kB1.94 kBWithin budget: 2.17 kB / 3.07 kB
use-lock-fn31.91 kB800 B657 BWithin budget: 800 B / 2.05 kB
use-map12.20 kB820 B716 BWithin budget: 820 B / 2.05 kB
use-media-query24.16 kB1.28 kB1.12 kBWithin budget: 1.28 kB / 2.05 kB
use-memoized-fn21.53 kB689 B552 BWithin budget: 689 B / 2.05 kB
use-online11.85 kB706 B587 BWithin budget: 706 B / 2.05 kB
use-previous1291 B211 B171 BWithin budget: 211 B / 2.05 kB
use-reset-state43.39 kB1.19 kB966 BWithin budget: 1.19 kB / 2.05 kB
use-resize-observer36.30 kB1.74 kB1.49 kBWithin budget: 1.74 kB / 2.05 kB
use-safe-state21.45 kB676 B530 BWithin budget: 676 B / 2.05 kB
use-session-storage28.60 kB2.17 kB1.94 kBWithin budget: 2.17 kB / 3.07 kB
use-set12.14 kB764 B665 BWithin budget: 764 B / 2.05 kB
use-throttle33.74 kB1.10 kB945 BWithin budget: 1.10 kB / 2.05 kB
use-throttle-fn44.31 kB1.35 kB1.19 kBWithin budget: 1.35 kB / 2.05 kB
use-timeout43.29 kB1.09 kB926 BWithin budget: 1.09 kB / 2.05 kB
use-toggle1820 B465 B360 BWithin budget: 465 B / 2.05 kB
use-unmounted-ref21.32 kB617 B498 BWithin budget: 617 B / 2.05 kB
use-websocket313.8 kB3.07 kB2.68 kBWithin budget: 3.07 kB / 3.07 kB
use-window-size12.13 kB792 B677 BWithin budget: 792 B / 2.05 kB
Unminified ESM · ES2022 · React external · Node.js zlib default gzip / Brotli settings90th percentile gzip: 2.17 kB

The report measures each unminified ES2022 entry and its reachable internal modules. React and React DOM stay external. gzip and Brotli use Node.js defaults, so these numbers are a consistent package baseline, not a prediction of your final application bundle.

Import what you need

Every Hook has a direct ESM entry such as better-hooks/use-media-query. The root better-hooks entry exposes the same API and relies on your bundler's tree shaking. Direct imports make the first module boundary obvious and are what the examples use.

The package has no runtime dependency beyond React, uses explicit exports, and declares sideEffects: false.

Share browser work only when it helps

Hooks share native work when subscribers truly observe the same source. Equal media queries reuse one channel, online state uses one listener pair per browser realm, and window-size subscribers share one resize listener. Instance-specific observers and connections stay separate when sharing would blur cancellation or error handling.

Timers, listeners, observers, and network work start after commit and stop when their owner changes or unmounts. Stable callback refs avoid rebuilding that work just because a callback received a new identity.

Measure the application you ship

Your bundler may minify, split, deduplicate, and transform this code differently. Check the finished application for bundle size, long tasks, subscription counts, and unnecessary rerenders. Package metrics are the starting point, not the last word.