React Flashcards

1
Q

Is React declarative or imperative?

A

It’s declarative. You say what you want to have happen rather than give step by step instructions.

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

What’s the syntax to create a new component called MyComponent?

A

Class MyComponent extends React.Component;

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

When is a component constructor function called?

A

Once, the first time the component is mounted (i.e. instantiated)

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

How do you change state inside a React component?

A

this.setState({ prop: value })

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

What are the two reasons to use a constructor in a component?

A

To initialize state or to bind event handlers to the class instance,

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

What are two requirements for a constructor function?

A

It should accept props as an argument and it should call super(props)

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

Does case matter in naming React components?

A

Yes, they must be uppercase or React will treat them as DOM tags

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

Difference between stateless and stateful components

A

Stateful are always class components, require constructor and set their state. Stateless functional components don’t have this, can’t use lifecycle functions like didMount;

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

Asynchronous setState() syntax?

A

this.setState((prevState, props) => ({
counter: prevState.counter + props.increment
}));

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

What’s wrong with this: this.handleClick(e)}>

A

A different callback is created with each render; if passed as a prop it may render twice. Use bind in constructor or use public class fields syntax.

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

Why is the index from an array not a good key for React?

A

If order changes, performance can suffer.

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

Why is data change without mutation important in React?

A
  1. Easier to undo/redo and time travel;
  2. Easier to track if changes have taken place to an object
  3. Performance: determining when to re-render.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a ‘controlled component’?

A

An input form where React controls state, e.g. input value = {this.state.value}.

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