M3-React Flashcards

1
Q

What is React?

A

A JavaScript library for building user interfaces

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

What is a React element?

A

It’s an object representing the DOM.

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

How do you mount a React element to the DOM?

A

react.render()

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

What is a React component?

A

It accepts arbitrary inputs (called “props”) and returns React elements describing a piece of UI.

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

How do you define a function component in React?

A
Example:
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
The first letter of the component name of the first letter should be capitalized. React treats components starting with lowercase letters as DOM tags.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you mount a component to the DOM?

A

ReactDOM.render()

Calling the render method of the ReactDOM object.

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

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

make sure there is a plugin -transform-react-jsx (answers need to be checked again)

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

Why must the React object be imported when authoring JSX in a module?

A

If you give some JSX to Babel, you will see that JSX is just sugar for React.createElement calls. This is why we need to import React if we use JSX.

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

What are props in React?

A

“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another.

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

How do you pass props to a component?

A

Use attribute. key-value format.

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

How do you write JavaScript expressions in JSX?

A

You are to write the expressions surrounded by curly brackets.

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

How do you create “class” component in React?

A

Example from React Official Documentation:

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you access props in a class component?

A

Use ‘this’ keyword. => this.props.name

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

What is the purpose of state in React?

A

controls what’s display on the page.

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

How do you pass an event handler to a React element?

A

???

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

What are controlled components?

A

set different values?

17
Q

What two props must you pass to an input for it to be “controlled”?

A

the value and onChange

18
Q

What Array method is commonly used to create a list of React elements?

A

map()

19
Q

What is the best value to use as a “key” prop when rendering lists?

A

something is unique is the best value.

20
Q

When does React call a component’s componentDidMount method?

A

is invoked immediately after a component is mounted

21
Q

Name three React.Component lifecycle methods.

A

not done

22
Q

How do you pass data to a child component?

A

not done