2

I'm wondering how deep you can pass forwardRef down in a nested app, and how would someone pass it down?

Something like this:

<Parent>
  <Child>
    ....
  </Child>
</Parent>

    <Child>
      <GrandChild>
          ....      
      </GrandChild>
    </Child>

        <GrandChild>
          <GreatGrandChild>
            ....
          </GreatGrandChild>
        </GrandChild>

            <GreatGrandChild>
              ....
            </GreatGrandChild>

and then use it in GreatGrandChild component or passing down the ref of and element in Parent down to GreatGrandChild

Misuti
  • 313
  • 1
  • 2
  • 8
  • Potential duplicate: https://stackoverflow.com/questions/50621471/access-a-nested-grand-child-component-in-a-parent-component – Kalinda Pride May 26 '21 at 20:23

1 Answers1

1

You could pass a ref as deep as you want but that seems inefficient.

One alternative would be to use the context API to set a ref in the producer (component containing the ref element) and use it in the consumer (child that will utilize the ref)

varoons
  • 3,807
  • 1
  • 16
  • 20