React-Effects Flashcards

1
Q

When is a component “mounted” to the DOM?

A

During the intial render of the component i.e. when it appears on the screen for the first time

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

What is a React Effect?

A

React Effect allows components to connect and sychronize with external systems such as various apis and servers to get and post data

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 when rendering a component should trigger a connection to a third party source.
You shouldn’t need an Effect if no external systems are involved with your components render

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

eWhen do Effects run?

A

Effects run after React commits a render of the component

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

the setup function

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 tell React to skip re-running an Effect function after every re-render of the component. You declare them as the second arguemnet of your use Effect function and they are held within an array

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

You would want to clean up from an Effect if you want to disconnect from an external source when the component is dismounted

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

after the return statement, you write an arrow function with code inside.

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, and one final time when the component unmounts (gets removed)

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