import { useEffect, useState } from "react"; export const useResizeKey = (debounceMs = 150) => { const [key, setKey] = useState(0); useEffect(() => { let t: number | undefined; const onResize = () => { window.clearTimeout(t); t = window.setTimeout(() => setKey((k) => k + 1), debounceMs); }; window.addEventListener("resize", onResize); return () => { window.removeEventListener("resize", onResize); window.clearTimeout(t); }; }, [debounceMs]); return key; }