React-Effects Flashcards

1
Q

When is a component “mounted” to the DOM?

A

After the component has been rendered or called.

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

What is a React Effect?

A

Effects let you specify side effects that are caused by rendering itself, rather than by a particular event.

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

When should you use an Effect and when should you not use an Effect?

A

You should use an Effect only when you are stepping out of your React code and want to sychronize with an external system

If there is no external system involved (for example, if you want to update a component’s state when some props or state change), you shouldn’t need an Effect

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

When do Effects run?

A

after the component has rendered, unmounted, and when the prop value has changed and appeared on the screen

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

What function is used to declare an Effect?

A

useEffect()

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

What are Effect dependencies and how do you declare them?

A

Effect dependencies stops the Effect from running after every render of the component if the dependency is the same as it was during the previous render

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

Why would you want to clean up from an Effect?

A

If the user is switching from one component to another. There are instances where you would want to stop and undo the effect from running again

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

How do you clean up from an Effect?

A

usinng the return keyword followed by the cleanup function

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

When does the cleanup function run?

A

React will call your cleanup function each time before the Effect runs again

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