Skip to content
EliteChart

useChart

Documentation


Documentation / @elitechart/react / useChart

code
function useChart(ref): ChartHandle | null;

Defined in: react/src/use-chart.ts:37

Read the live engine handle from a <Chart /> ref.

Returns null until the chart engine boots on first paint, and after the component unmounts. Triggers a re-render when the handle becomes available so consumers can register listeners or drawings on the same render.

Parameters

ref

RefObject<ChartRef | null>

Returns

ChartHandle | null

Example

code
const ref = useRef<ChartRef>(null);
const handle = useChart(ref);
useEffect(() => {
  if (handle === null) return;
  return handle.on('crosshair:move', () => undefined);
}, [handle]);
return <Chart ref={ref} series={series} />;