BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/fancy/use-debounced-dimensions

Use Debounced Dimensions

fancy/use-debounced-dimensions
FreeHook

A hook component.

Install it

npx shadcn@latest add https://www.fancycomponents.dev/r/use-debounced-dimensions.json

Source

hooks/use-debounced-dimensions.tswww.fancycomponents.dev/r/use-debounced-dimensions.json
1import { RefObject, useEffect, useState } from "react"
2
3interface Dimensions {
4 width: number
5 height: number
6}
7
8export function useDimensions(
9 ref: RefObject<HTMLElement | SVGElement | null>
10): Dimensions {
11 const [dimensions, setDimensions] = useState<Dimensions>({
12 width: 0,
13 height: 0,
14 })
15
16 useEffect(() => {
17 let timeoutId: NodeJS.Timeout
18
19 const updateDimensions = () => {
20 if (ref.current) {
21 const { width, height } = ref.current.getBoundingClientRect()
22 setDimensions({ width, height })
23 }
24 }
25
26 const debouncedUpdateDimensions = () => {
27 clearTimeout(timeoutId)
28 timeoutId = setTimeout(updateDimensions, 250) // Wait 250ms after resize ends
29 }
30
31 // Initial measurement
32 updateDimensions()
33
34 window.addEventListener("resize", debouncedUpdateDimensions)
35
36 return () => {
37 window.removeEventListener("resize", debouncedUpdateDimensions)
38 clearTimeout(timeoutId)
39 }
40 }, [ref])
41
42 return dimensions
43}

Files it writes

  • hooks/use-debounced-dimensions

Facts

Registry
fancy
Type
registry:hook
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

www.fancycomponents.dev danielpetho/fancy on GitHub Raw registry item This item as JSON

More from fancy

All 158 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Use Detect Browseruse-detect-browserfancyHooksFreeno deps
Use Dimensionsuse-dimensionsfancyHooksFreeno deps
Use Elastic Line Eventsuse-elastic-line-eventsfancyHooksFreeno deps
Use Line Breakdownuse-line-breakdownfancyHooksFreeno deps
Use Line Countuse-line-countfancyHooksFreeno deps
Use Mounteduse-mountedfancyHooksFreeno deps
Use Mouse Positionuse-mouse-positionfancyHooksFreeno deps
Use Mouse Position Refuse-mouse-position-reffancyHooksFreeno deps
BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex

BlockDex

Built by

Kynth Studio

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

BlockDex