I've implemented my ref forwarding with useRef hook and function components the same way you did, but I'm still getting inputRef.current is undefined and the warning "Function components cannot be given refs."
Hey Renato, thanks so much for the response! Your example convinced me that there was something else that was wrong in my app. It turns out that my "forwardRef(Input);" was wrapped in another HOC that was not passing in ref as the extra second argument. So I removed the HOC and now it works, thanks a lot for your help!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've implemented my ref forwarding with useRef hook and function components the same way you did, but I'm still getting inputRef.current is undefined and the warning "Function components cannot be given refs."
According to React docs, you need to implement ref forwarding using the useImperativeHandle hook: reactjs.org/docs/hooks-reference.h...
Hello z2lai, thanks by comment.
I implemented the example in this post for you to see: github.com/renatobentorocha/forwar....
The useRef hook is used to persist an object reference even after a component to be rerendered: reactjs.org/docs/hooks-reference.h...
Hey Renato, thanks so much for the response! Your example convinced me that there was something else that was wrong in my app. It turns out that my "forwardRef(Input);" was wrapped in another HOC that was not passing in ref as the extra second argument. So I removed the HOC and now it works, thanks a lot for your help!