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

Feedback


Solution 1:

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

    const ContaineModal = ({modalRef}) => {
    return 
}


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: https://reactjs.org/docs/forwarding-refs.html.

Frequently Asked Questions