react hook function from child to child code example
Example: react hooks call child fuynction
export default function Parent() {
const myref=useRef();
const handleOnClick = () => {
if(myref.current) {
myref.current.sayHi();
}
}
return (
<Child ref={myref} />
<button onClick={handleOnClick}>Click me</button>
);
}
export default function Child() {
const sayHi = () => {
console.log('hi');
};
return (<div>Hello</div>);
}