DEV Community

loading...

Discussion on: Understanding the use of useRef hook & forwardRef in React

Collapse
psiho profile image
Mirko Vukušić • Edited

Oh, you definetly should mention other uses of useRef! It's really incomplete and useRef is for far more than just refferencing elements. From docs: 'However, useRef() is useful for more than the ref attribute. It’s handy for keeping any mutable value around similar to how you’d use instance fields in classes.'.

Collapse
sajithpradeep profile image
Sajith Pradeep Author

Thanks for this comment. Very valuable info. I will definitely take a look at this and update this post with my learning!

Collapse
psiho profile image
Mirko Vukušić • Edited

Just one example that I actually use more than refferencing elements... When you want to avoid running useEffect on mount of the component: stackoverflow.com/questions/594926...

More examples here: dmitripavlutin.com/react-useref-gu...

Thread Thread
sajithpradeep profile image
Sajith Pradeep Author

Thanks for this! I'm sure this will come in handy for me.