1export default function Parent() {
2 const myref=useRef();
3
4 const handleOnClick = () => {
5 if(myref.current) {
6 myref.current.sayHi();
7 }
8 }
9
10 return (
11 <Child ref={myref} />
12 <button onClick={handleOnClick}>Click me</button>
13 );
14}
15export default function Child() {
16 const sayHi = () => {
17 console.log('hi');
18 };
19 return (<div>Hello</div>);
20}
21