I am getting the error: 'ResizeObserver' only refers to a type, but is being used as a value here
when attempting to use ResizeObserver in React with TypeScript.
I have the following interface defined as TypeScript does not include definitions:
interface ResizeObserver {
observe(target: Element): void;
unobserve(target: Element): void;
disconnect(): void;
}
And I am using it in the following component:
const useWidth = () => {
const ref = useRef<HTMLObjectElement>(null);
const [width, setWidth] = useState(0);
useLayoutEffect(() => {
var resizeObserver = new ResizeObserver(() => console.log("blah blah blah"))
resizeObserver.observe(ref.current)
return () => resizeObserver.disconnect()
}, [ref.current])
return [ref, width];
}