Skeleton screens typically require maintaining a separate hand-crafted component for every real component, causing them to fall out of sync whenever the UI changes. This tutorial presents an alternative approach: render the real component with mock data, use getBoundingClientRect() to measure the DOM, and overlay shimmer blocks at the exact positions of leaf elements. The technique is built step by step β from a single shimmer overlay, to per-element measurement, to stealing border-radius via getComputedStyle(), to wiring it all together with useLayoutEffect and React.cloneElement for mock data injection. Edge cases covered include zero-dimension elements, images without explicit sizes, SVGs, async components, and window resize during loading. The result is a Shimmer wrapper component where the real component IS the skeleton, so layout changes automatically propagate to the loading state without any manual maintenance.
Table of contents
The maintenance trap πWhat existing libraries do (and donβt do) πStep 1: The dumbest possible version πStep 2: Measure the DOM πStep 3: Steal the border radius πStep 4: The shimmer animation πFrom static HTML to a real app πStep 5: Wire it up with useLayoutEffect πStep 6: Handle edge cases πDesigning mock data πThe tradeoffs πReferences πSort: