Hi David, happy to hear you like this approach!
I used forwardRef
and useImparativeHandle
in order to be able to call the function open()
from the parent component with a reference.
In “Navigation” component (parent) I get a reference to the “Menu” component (child). Through that (parent) reference, I want to be able to call the (child) component function open()
.
I think I understand this forwardRef/useImparativeHandle as a way to access a reference from another reference.
Does this explanation kind of makes sense to you too?
In the documentation the following sentence speaks to me:
In this example, a parent component that renders
<FancyInput ref={inputRef} />
would be able to callinputRef.current.focus()
.
Best regards
David