UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

21 lines (20 loc) 692 B
'use client'; import * as React from 'react'; import { useChartsContext } from "./ChartsProvider/index.mjs"; /** * The `useChartApiContext` hook provides access to the chart API. * This is only available when the chart is rendered within a chart or a `ChartsDataProvider` component. * If you want to access the chart API outside those components, you should use the `apiRef` prop instead. * @example * const apiRef = useChartApiContext<ChartApi<'bar'>>(); */ export function useChartApiContext() { const { publicAPI } = useChartsContext(); const apiRef = React.useRef(publicAPI); React.useEffect(() => { apiRef.current = publicAPI; }, [publicAPI]); return apiRef; }