07. Imperative Programming Flashcards

(8 cards)

1
Q

What is useRef in React?

A

useRef is a hook in React that provides a mutable object called a ref, which can hold a mutable value and persists across renders.

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

How is useRef different from useState in React?

A

Unlike useState, useRef doesn’t trigger a re-render when its value changes. It’s often used for mutable values that don’t affect the rendering.

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

Can useRef be used to hold a mutable value that persists across renders?

A

Yes, the primary purpose of useRef is to hold mutable values that persist across renders without causing re-renders.

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

What is the common use case for useRef in React?

A

A common use case is accessing and interacting with the DOM, as useRef can hold a reference to a DOM element.

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

Can useRef be used to trigger re-renders in React?

A

No, changing the value of a ref created with useRef does not trigger a re-render.

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

Can useRef be used to persist values between function calls?

A

Yes, useRef values persist across renders, making them suitable for persisting values between function calls without triggering re-renders.

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

How can you access the current value of a ref created with useRef?

A

Use myRef.current to access the current value of a ref created with useRef.

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