Class based react Flashcards

1
Q

What does super() do in a class based component?

A

it calls the parents classes constructor. So when you extend from React.Component it calls using super() calls React.Component’s constructor function.

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

When does componentDidMount run?

A

Immediately after the first render of a component.

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

What triggers a component to run the render method again?

A

Whenever props or state change a component will re render.

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

What is the equivalent to componentDidMount when working in a functional component?

A

a useEffect with an empty dependency array.

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

When does componentDidUpdate run?

A

If you define the componentDidUpdate method, React will call it immediately after your component has been re-rendered with updated props or state. This method is not called for the initial render.

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

When does the componentWillUnmount run? What is it useful for?

A

If you define the componentWillUnmount method, React will call it before your component is removed (unmounted) from the screen. This is a common place to cancel data fetching or remove subscriptions.

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

What does a Redux Provider do? How does it do this?

A

The <Provider> component makes the Redux store available to any nested components that need to access the Redux store.</Provider>

It uses React’s Context mechanism to do this.

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

What does React context let you do ?

A

Context lets components pass information deep down without explicitly passing props.

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