React - useRef Flashcards

1
Q

What are the 2 rules to remember about references?

A
  1. The value of the reference is persisted (stays the same) between component re-renderings;
  2. Updating a reference doesn’t trigger a component re-rendering.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many arguments does useRef( ) accept?

A

one argument, the references initial value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 2 main differences between references and state?

A
  1. Updating a reference doesn’t trigger re-rendering, while updating the state makes the component re-render.
  2. 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).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are reference updates asynchronous?

A

No they are synchronous, their new value can be accessed straight away.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly