1const FancyButton = React.forwardRef((props, ref) => (
2 <button ref={ref} className="FancyButton">
3 {props.children}
4 </button>
5));
6
7// You can now get a ref directly to the DOM button:
8const ref = React.createRef();
9<FancyButton ref={ref}>Click me!</FancyButton>;
1import {useRef} from 'react';
2
3// hten define the ref
4const inputRef = useRef(null);
5
6// then use it in the tag
7<section ref={inputRef} >...</section>
8