React Lifecycle & Lifecycle methods Flashcards

1
Q

What is the first phase of a React Lifecycle?

A

An instance of the component is created and two methods are called: GetDefaultProps and GetInitialState

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

What are two methods called on the initialization on creation of a component?

A

GetDefaultProps: is used to define any default props.

getInitialState: enables to set the initial state value, that is accessible inside the component via this.state.

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

What happens after the constructor define props and state?

A

componentWillMount is called and than the render method is executed.

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

What does the render method return on initialization?

A

It will return component markup which can be in the form of a single child or null/false.

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

After the first render method, what is called next?

A

ComponentDidMount

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

When is componentWillUnmount get called?

A

Before the component is removed from the DOM.

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

What is componentDidMount?

A

This is invoked immediately after mounting occurs, aka the first execution of render. Any changing of state in here will trigger another execution of render.

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

What is componentWillMount?

A

It is invoked immediately before mounting occurs. It is called before the first render(), thus setting state synchronously in here will not trigger a render.

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

props

A

this.props contains the props that were defined by the caller of the component.

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

state

A

contains data specific to this component that may change over time. The state is user defined.

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

What should you never do with state?

A

You should never mutate state, to set state call setState() to replace the state instead of mutating it.

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