React Flashcards

1
Q

Why do you need to import React in order to use JSX?

A

Because Babel transpiles JSX into React.createElement( )

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

Why do React component names need to start with a capital letter?

A

Because this is how React knows it is a React component. Otherwise, it would render it as an HTML tag (i.e., class thing would be rendered as ).

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

What component lifecycle method(s) are triggered when a component is mounted?

A
  1. constructor( ) 2. getDerivedStateFromProps( ) (static) 3. render( ) 4. componentDidMount( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What component lifecycle method(s) are triggered when a component is updated?

A
  1. getDerivedStateFromProps( ) 2. shouldComponentUpdate( ) 3. render( ) 4. getSnapshotBeforeUpdate( ) 5. componentDidUpdate( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What component lifecycle method(s) are triggered when a component is unmounted?

A

componentWillUnmount( )

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

What component lifecycle method(s) are triggered when a component encounters an error during a lifecycle method?

A

componentDidCatch( )

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

Why should you fetch data in componentDidMount and not the constructor?

A

Because the data you need to render might not be available when the component is rendering. By fetching in componentDidMount, the component can render once safely without the fetched data and then again once it has been placed into state.

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

How might you benefit from “lifting the state up” in a React application.

A

Placing state high enough allows state values to be shared by sibling components. It also allows you to create purely presentational components.

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

What is the purpose of useEffect’s return value?

A

If you return a function from useEffect, React runs it when the component unmounts.

For example, if you add a scroll listener as part of useEffect, you can remove that listener by returning a cleanup function that calls removeEventListener.

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