DEV Community

loading...

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

Collapse
sajithpradeep profile image
Sajith Pradeep Author

Thanks for bringing in this perspective. I will try this out. It makes more sense as there are multiple instances where forwarding the hooks is required and this helps us stick to the DRY principle.

Collapse
karem1986 profile image
Karem

could u please explain what is the DRY principle? and if you have the link to test the code from github that would be awesome please :)

Thread Thread
lukeshiru profile image
LUKESHIRU

The DRY principle is just an acronym for "Don't Repeat Yourself". Basically is to avoid having code duplication by moving some logic into reusable functions. In this particular scenario, having a function like withRef helps with DRY because we don't need to write that logic every time we have a component like that, we just call the withRef function and done :)

Thread Thread
karem1986 profile image
Karem

Thank you!