e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
24 lines
608 B
TypeScript
24 lines
608 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
export function useMeasuredHeight<T extends HTMLElement>() {
|
|
const ref = useRef<T>(null);
|
|
const [height, setHeight] = useState(0);
|
|
|
|
useEffect(() => {
|
|
const element = ref.current;
|
|
if (!element || typeof ResizeObserver === "undefined") return;
|
|
|
|
const updateHeight = () =>
|
|
setHeight(element.getBoundingClientRect().height);
|
|
updateHeight();
|
|
|
|
const observer = new ResizeObserver(() => updateHeight());
|
|
observer.observe(element);
|
|
return () => observer.disconnect();
|
|
}, []);
|
|
|
|
return { ref, height };
|
|
}
|