React HooksLesson 50Free preview
React useRef
This lesson is part of React · All levels
Summary
UseRef returns a mutable object that survives for the life of the component without causing a re-rendering when the contents are changed. The object .current is very useful for storing the DOM element references, timer, or value of the previous render. Unlike useState, changing ref does not trigger rendering.
Key points
- UseRef returns the object as {current}
- Changing the .current does not trigger a re-rendering
- Often used to store references to DOM elements
- Ref value stays stable between renders
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.