0

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

isherwood
  • 58,414
  • 16
  • 114
  • 157
Danko
  • 55
  • 2
  • 6

0 Answers0