Did you mean to use React.forwardRef()?

JavaScript
const FancyButton = React.forwardRef((props, ref) => (
  <button ref={ref} className="FancyButton">
    {props.children}
  </button>
));

// You can now get a ref directly to the DOM button:
const ref = React.createRef();
<FancyButton ref={ref}>Click me!</FancyButton>;import {useRef} from 'react';

// hten define the ref
const inputRef = useRef(null);

// then use it in the tag
<section ref={inputRef} >...</section>

Source

Also in JavaScript: