David Dal Busco
1 min readJun 17, 2020

--

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 call inputRef.current.focus().

Best regards
David

--

--

David Dal Busco
David Dal Busco

Written by David Dal Busco

Freelancer by day | Creator of Juno.build by night

Responses (1)