Files
t3code/apps/web/src/hooks/useElementWidth.ts
T
Julius Marmingeandcodex c8aea5db0b Map thread panel into title bar and sidebar
- Add thread-panel presentation logic for inline vs popover layouts
- Move thread details controls into the chat header/sidebar flow
- Add shared wait-for-atom helper and workspace display name parsing

Co-authored-by: codex <[email protected]>
2026-08-15 16:49:46 +02:00

26 lines
775 B
TypeScript

import { useLayoutEffect, useState } from "react";
export function useElementWidth<T extends HTMLElement>() {
const [element, setElement] = useState<T | null>(null);
const [width, setWidth] = useState<number | null>(null);
useLayoutEffect(() => {
if (!element) return;
const update = (nextWidth: number) => {
setWidth((currentWidth) => (currentWidth === nextWidth ? currentWidth : nextWidth));
};
update(element.getBoundingClientRect().width);
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(([entry]) => {
if (entry) update(entry.contentRect.width);
});
observer.observe(element);
return () => observer.disconnect();
}, [element]);
return [setElement, width] as const;
}