Thanks for this articles with full of details and examples.
It seems to be quite complex in term of use and implementation and hard to remember. Should developper really rely on this ?
I run my own programming blog called Unicorn Utterances, I do development of all kinds, usually focusing on web development.
I collect retro video games 🎮, like reading 📖, love teaching 👨🏫
Absolutely! Keep in mind, using refs isn't simply some philosophical rationale of "correctness", they prevent renders. This means that if you're, say, using a timer to keep track of a setTimeout to clear later (like in one of these examples), you don't want to trigger a re-render.
Not only can a re-render during that change cause performance issues, but also introduce behavioral issues as well.
While this article is long to create a more cohesive story, if you wanted a TL;DR it'd be something along the lines of:
"useRef for data causes no-rerenders. Use it wisely"
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.
Thanks for this articles with full of details and examples.
It seems to be quite complex in term of use and implementation and hard to remember. Should developper really rely on this ?
Absolutely! Keep in mind, using refs isn't simply some philosophical rationale of "correctness", they prevent renders. This means that if you're, say, using a timer to keep track of a
setTimeout
to clear later (like in one of these examples), you don't want to trigger a re-render.Not only can a re-render during that change cause performance issues, but also introduce behavioral issues as well.
While this article is long to create a more cohesive story, if you wanted a TL;DR it'd be something along the lines of:
"useRef for data causes no-rerenders. Use it wisely"