Using React Refs to Pass Ref from Parent Component to Child Component


Solution 1:

Attain this by setting the ref on the desired div within the ContainerModal element, as shown below:

    const ContaineModal = ({modalRef}) => {

Solution 2:

I recommend checking out Forwarding Ref in React, which allows you to pass a tag from the parent to the child. The official documentation provides a code example that demonstrates this technique. follow this link to learn more:

Frequently Asked Questions