import React , { useContext , useEffect } from 'react' ; import { Chart } from '@elastic/charts' ; import { ChartPointerEventContext } from './chart_pointer_event_context' ; export function useChartPointerEventContext ( ) { const context = useContext ( ChartPointerEventContext ) ; if ( ! context ) { throw new Error ( 'Missing ChartPointerEventContext provider' ) ; } const { pointerEvent } = context ; const chartRef = React . createRef < Chart > ( ) ; useEffect ( ( ) => { if ( pointerEvent && chartRef . current ) { chartRef . current . dispatchExternalPointerEvent ( pointerEvent ) ; } } , [ pointerEvent , chartRef ] ) ; return { ... context , chartRef } ; }