Spaces:
Sleeping
Sleeping
Download befree-frontend/hooks/useResizeObserver.ts from Coeinterns/bank-statement-api: direct link, hf CLI and curl.
- Browser
- Download file 621 Bytes
-
https://huggingface.co/spaces/Coeinterns/bank-statement-api/resolve/main/befree-frontend/hooks/useResizeObserver.ts
- Command line
-
hf download hf://spaces/Coeinterns/bank-statement-api/befree-frontend/hooks/useResizeObserver.ts
-
curl -L -o useResizeObserver.ts https://huggingface.co/spaces/Coeinterns/bank-statement-api/resolve/main/befree-frontend/hooks/useResizeObserver.ts
621 Bytes
| import { useState, useEffect, RefObject } from 'react'; | |
| export function useResizeObserver(ref: RefObject<HTMLElement>) { | |
| const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); | |
| useEffect(() => { | |
| const element = ref.current; | |
| if (!element) return; | |
| const observer = new ResizeObserver((entries) => { | |
| if (entries[0]) { | |
| const { width, height } = entries[0].contentRect; | |
| setDimensions({ width, height }); | |
| } | |
| }); | |
| observer.observe(element); | |
| return () => { | |
| observer.disconnect(); | |
| }; | |
| }, [ref]); | |
| return dimensions; | |
| } | |