import { useEffect, useRef } from 'react' import { widgetStoreActions } from '../widgets/stores/widget-store' /** * Registers a DOM element ref and an ECharts instance ref with the widget store. * This allows other parts of the application (e.g., screenshot export) to access the widget's DOM element. * * @param widgetId - The widget ID to register the refs under. * @returns An object with `ref` (DOM element) and `instance` (ECharts instance) refs. * * @example * ```tsx * function MyWidget({ id }: { id: string }) { * const { ref } = useWidgetRef(id) * * return
Widget content
* } * ``` */ export function useWidgetRef( widgetId: string, ) { const ref = useRef(null) const instance = useRef(null) useEffect(() => { if (ref.current) { widgetStoreActions.setWidget(widgetId, { refUI: ref, instance: instance }) } }, [widgetId]) return { ref, instance } }