MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / MeasuredChartFrame

Function MeasuredChartFrame

ui/src/components/MeasuredChartFrame.tsx:18–44  ·  view source on GitHub ↗
({ className, children }: MeasuredChartFrameProps)

Source from the content-addressed store, hash-verified

16 * during route transitions, so gate chart mounting on a measured frame.
17 */
18export function MeasuredChartFrame({ className, children }: MeasuredChartFrameProps) {
19 const ref = useRef<HTMLDivElement | null>(null)
20 const [size, setSize] = useState<ChartFrameSize | null>(null)
21
22 useEffect(() => {
23 const el = ref.current
24 if (!el) return
25
26 const measure = () => {
27 const rect = el.getBoundingClientRect()
28 setSize(rect.width > 0 && rect.height > 0
29 ? { width: Math.floor(rect.width), height: Math.floor(rect.height) }
30 : null)
31 }
32
33 measure()
34 const ro = new ResizeObserver(measure)
35 ro.observe(el)
36 return () => ro.disconnect()
37 }, [])
38
39 return (
40 <div ref={ref} className={className}>
41 {size ? (typeof children === 'function' ? children(size) : children) : null}
42 </div>
43 )
44}

Callers

nothing calls this directly

Calls 2

measureFunction · 0.70
disconnectMethod · 0.45

Tested by

no test coverage detected