Can someone explain me how to use UseRef in React? What it is and what it does? I have tried to find tutorial online but I still can't understand that stuff. Thank you so much !
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
There are two use cases of useRef :
Retain data across multiple rerender of the component
Get reference to the DOM element / tag within the component
The above values are accessed using
.current
of the value.Thank you for that ! Much appreciated !
The short answer is that you can use
useRef
when you want to persist some value in multiple renders of your component (similar touseState
) but you don't want to re-render that component when that value changes.Tyler McGinnis has one of the best explanation on how to use useRef
Thank you so much! That link you've shared is very useful.