From the article it seems your understanding of the useRef hook is a bit limited. Another way to describe a ref is to say: a piece of state that does not cause a re-render when changed. On top of that it is constructed in a way that ensures it is 'referentially stable'.
I'm a full-stack developer with a passion for building beautiful and accessible UI. Everyone has a place on the internet, and it's up to developers to keep it that way.
I'm definitely still learning, and this was very helpful. I'll be amending some notes and testing this approach out in some code ASAP. Thank you for taking the time to help me understand this topic more deeply.
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.
Hello, thank you for writing the article!
From the article it seems your understanding of the
useRef
hook is a bit limited. Another way to describe aref
is to say: a piece of state that does not cause a re-render when changed. On top of that it is constructed in a way that ensures it is 'referentially stable'.You could see it like this:
The
useRef
function ensures thatmyRef
is attached to the 'instance' of your component and will be removed once the component is unmounted.useRef
can be very useful in a variety of situations, here is an example:Here we are using
useRef
instead of passingf
as a dependency touseEffect
to prevent listeners to be added and removed on each render.I hope this provides a bit of extra understanding.
I really appreciate your comment!
I'm definitely still learning, and this was very helpful. I'll be amending some notes and testing this approach out in some code ASAP. Thank you for taking the time to help me understand this topic more deeply.