How to pass ref from child to parent through several nested components?
forwardRef
working only for directly child to parent way
Child:
const Menu = forwardRef((props, menuRef) => {
return <div ref={menuRef}></div>
}
Parent:
const Header = () => {
const menuRef = useRef(null)
return {<Menu ref={menuRef}/>}
}
Parent of the parent:
const Layout = () => {
...here I want ref from child