BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ericts-ui/use-element-size-map

useElementSizeMap

ericts-ui/use-element-size-map
FreeHook

A client-safe React hook that measures multiple keyed element sizes with ResizeObserver so animated shells can morph to active content.

Install it

npx shadcn@latest add https://ui.ericts.com/r/use-element-size-map.json

Source

registry/base/hooks/use-element-size-map.tsui.ericts.com/r/use-element-size-map.json
1"use client";
2
3import { useCallback, useEffect, useRef, useState } from "react";
4
5export type ElementSize = {
6 width: number;
7 height: number;
8};
9
10/**
11 * Tracks the rendered size of multiple keyed elements with ResizeObserver.
12 *
13 * Use it when an animated shell, indicator, toolbar, or floating panel needs to
14 * move toward the measured width/height of whichever keyed element is active.
15 *
16 * @example
17 * const { setMeasureRef, sizes } = useElementSizeMap<HTMLDivElement>();
18 * const activeSize = sizes[activeId];
19 *
20 * return (
21 * <>
22 * <div aria-hidden className="invisible absolute">
23 * {items.map((item) => (
24 * <div key={item.id} ref={setMeasureRef(item.id)}>
25 * {item.content}
26 * </div>
27 * ))}
28 * </div>
29 * <motion.div animate={activeSize}>
30 * {activeItem.content}
31 * </motion.div>
32 * </>
33 * );
34 */
35export function useElementSizeMap<T extends HTMLElement>(threshold = 0.5) {
36 const [sizes, setSizes] = useState<Record<string, ElementSize>>({});
37 const observerRef = useRef<ResizeObserver | null>(null);
38 const elements = useRef(new Map<string, T>());
39 const idsByElement = useRef(new WeakMap<Element, string>());
40 const callbacks = useRef(new Map<string, (node: T | null) => void>());
41 const thresholdRef = useRef(threshold);
42
43 useEffect(() => {
44 thresholdRef.current = threshold;
45 }, [threshold]);
46
47 useEffect(() => {
48 const activeElements = elements.current;
49
50 return () => {
51 observerRef.current?.disconnect();
52 observerRef.current = null;
53 activeElements.clear();
54 idsByElement.current = new WeakMap();
55 };
56 }, []);
57
58 const updateSizes = useCallback(
59 (updates: ReadonlyArray<readonly [string, ElementSize]>) => {
60 setSizes((current) => {
61 let next = current;
62
63 for (const [id, nextSize] of updates) {
64 const currentSize = current[id];
65
66 if (
67 currentSize &&
68 Math.abs(currentSize.width - nextSize.width) <=
69 thresholdRef.current &&
70 Math.abs(currentSize.height - nextSize.height) <=
71 thresholdRef.current
72 ) {
73 continue;
74 }
75
76 if (next === current) {
77 next = { ...current };
78 }
79
80 next[id] = nextSize;
81 }
82
83 return next;
84 });
85 },
86 [],
87 );
88
89 const getObserver = useCallback(() => {
90 if (typeof ResizeObserver === "undefined") return null;
91
92// … truncated

Files it writes

  • registry/base/hooks/use-element-size-map.ts

Facts

Registry
ericts-ui
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-08
Last confirmed
yesterday

Go to the source

Docs on ericts-ui ui.ericts.com EricTsai83/ericts-ui on GitHub Raw registry item This item as JSON

More from ericts-ui

All 38 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useElementHeightuse-element-heightericts-uiHooksFreeno deps
useReducedMotionuse-reduced-motionericts-uiHooksFreeno deps
useScrollAnchoruse-scroll-anchorericts-uiHooksFreeno deps
useScrollProgressuse-scroll-progressericts-uiHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

KitGrade

SaaS starter kits, scored from measured facts

kitgrade.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex