React - useRef Flashcards
1
Q
What are the 2 rules to remember about references?
A
- The value of the reference is persisted (stays the same) between component re-renderings;
- Updating a reference doesn’t trigger a component re-rendering.
2
Q
How many arguments does useRef( ) accept?
A
one argument, the references initial value.
3
Q
What special property does a reference have ?
A
The “current” property.
reference.current accesses the reference value, and reference.current = newValue updates the reference value.
4
Q
What are the 2 main differences between references and state?
A
- Updating a reference doesn’t trigger re-rendering, while updating the state makes the component re-render.
- The reference update is synchronous (the updated reference value is available right away), while the state update is asynchronous (the state variable is updated after re-rendering).
5
Q
Are reference updates asynchronous?
A
No they are synchronous, their new value can be accessed straight away.