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

Written by

Freelancer by day | Creator of DeckDeckGo by night | Organizer of the Ionic and IndieHackers Zürich Meetup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store