Hooks Flashcards

1
Q

useEffect() parameters?

A

useEffect() hook takes function as a parameter which is executed every time the dependency array changes

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

useEffect() syntax

A

useEffect(arrow function, [dependency variables])

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

make useEffect() call only once ?

A

useEffect(arrow function, [ ])
Having an empty dependency array makes an useEffect() call only once.

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

useEffect() to clean up

A

The arrow function in the useEffect() can return a function that can be used to clean up

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

useEffect() to make an API call

A

Call an API inside arrow function of useEffect() and give empty dependency array. So that API gets called only once.

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

useMemo() hook is used for ?

A

It is used to cache/memoize the output of a function( generally the long taking process)

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

useMemo() syntax?

A

useMemo syntax is similar to other hooks like useEffect().it takes a arrow function and a dependency array.

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

useMemo() example

A

const num = useMemo(()=>{return slowfunction(number)}, [number]) . when number changes the cache refreshes

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

how useEffect() triggers

A

useEffect() gets triggered every time the component renders or re-renders

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

how useState() works?

A

whenever the state(const num = useState() , if num) changes it causes the component to re-render

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

difference between refs and state

A

when the state changes it causes component to re-render while the change in the ref doesnot cause component to re-render

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

useRef() syntax

A

const num = useRef(0); it returns a object with current as property

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

usecase of useRef()

A

they are generally used to reference the elements in the HTML , it is also used to persist the value between re-renders.

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

what useCallback() does?

A

useCallback() is similar to useMemo().the difference is useMemo() caches/memoizes the value where as useCallback() caches the entire function

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

why useCallback() is used?

A

to check for referential equality

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