// Tracks the rendered size of a ref'd element via ResizeObserver.
// Shared by BarChart and LineChart for responsive width.
function useSize(ref) {
  const [size, setSize] = React.useState({ w: 600, h: 220 });
  React.useLayoutEffect(() => {
    if (!ref.current) return;
    const ro = new ResizeObserver(entries => {
      for (const e of entries) {
        setSize({ w: e.contentRect.width, h: e.contentRect.height });
      }
    });
    ro.observe(ref.current);
    return () => ro.disconnect();
  }, [ref]);
  return size;
}

Object.assign(window, { useSize });
