Fundamentals Flashcards

1
Q

What syntax do you use to render the App component into an HTML element with id “root”?

A

ReactDOM.render(, document.getElementById(“root”));

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

What’s a good use case to using a function while rendering a dynamic list of items?

A

If we need to compute a value based on properties of items in the loop.

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

What’s the right syntax to assign the function doSomething as the handler of a click event?

A

onClick={doSomething}

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

When is it recommended to pass this.setState a function instead of an object

A

When the new state depends on the old state

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

We have a boolean X. We want to render component A if X is true, and component B if X is false. Which is correct?

A

{ X ? <a></a> : <b></b> }

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

What function can be used to change the state of a React component?

A

this.setState

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

What are the 2 objects that act as the input of a Class-based component?

A

state and props

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

When is the class component syntax needed?

A

When we need to manage state or use lifecycle methods

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

A module in a file myClass.js exports a class like this:

export default MyClass;
How can MyClass be imported in another module?

A

import My from ‘./myClass’;

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

What is a good reason to use a state library like Flux or Redux?

A

Root components get too bloated with maintaining state.

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

What is a good lifecycle method to use when you want to fetch data from a webservice?

A

componentDidMount

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

In the root of a React application there is a folder named `my-component’. It contains an index.js file with a component named ‘MyComponent’ that gets exported as the default. What is the best way to import this component?

A

import MyComponent from ‘./my-component’;

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

Why must setState be used to add to the state?

A

Because doing so triggers the re-rendering of the involved components.

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

What problem does context solve?

A

Passing on the same data via props over and over again

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

What is React’s approach to separation of concerns?

A

What’s displayed in the browser is only a reflection of the state of the application.

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

What is JSX?

A

It is a HTML-like syntax that translates to JavaScript.

17
Q

Why are propTypes useful?

A

They declare your component’s expectations.