Ref Demo - Forwarding Ref with React.forwardRef

How this works

We create a ref in the parent component, and then pass it using 'ref' (a special attribute, but not a 'props', mostly like the 'key'). And then we use React.forwardRef to pass 'ref' along with 'props' to the child component. After that, we can control the child component's DOM element from the parent component.


Codepen Demo

https://codepen.io/deniapps/pen/ZEWGGRe