We expose additional methods on chart objects, which are available when you have a reference to an instance of a chart. Refs provide a way to access React elements created in the render method. For example, when you have a ref to a chart, you can call the ping method which will ping the clicked items in the chart. For all instance methods, see the API Reference.
Creating a ref in a functional component
If you are using React 16.8 or above then you have access to the hooks API and can use the useRef() hook in your functional components.
const MyFunctionalComponent = (props) => {
const { items } = props;
const chartRef = React.useRef(null);
const ping = ({ id }) => {
if (id) {
chartRef.current.ping({ [id]: true });
}
};
return (
<Chart ref={chartRef} items={items} positions={positions} onClick={ping} />
);
};