React JS 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

A JavaScript object created using React that models a DOM element

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

ReactDOM.render(newReactElement, existingDOMElement);

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

What is JSX?

A

It is a syntax extension of JavaScript that is used to describe HTML elements, and can be converted into React elements using Babel

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

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

A

JSX code is syntactic sugar for a React element

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

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

A

You assign the module.exports.module.rules[0].use.loader = ‘babel-loader’ in the webpack.config.js file

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

What is a React component?

A

A JavaScript function/class that takes in a props argument to construct a React element

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

How do you define a function component in React?

A
function SomeComponent([props]) {
return ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you mount a component to the DOM?

A

ReactDOM.render(Some Component />, existingDOMElement);

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

Why do you need to capitalize React components?

A

React treats components starting with a lowercase letter as a DOM tag (converts it to string)

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

What are props in React?

A

They are objects holding the “properties” to be used in making a React element

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

How do you pass props to a component?

A

You specify them as you would write attributes in an HTML element opening tag

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

How do you write JavaScript expressions in JSX?

A

between curly braces {expression}

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

How do you create “class” component in React?

A
class SomeComponent extends React.Component {
render() {
return ...
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you access props in a class component?

A

this.props

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

What is the purpose of state in React?

A

They keep track of values in a React element that change over time

17
Q

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

A

You can pass it as a prop in the React element

18
Q

What are controlled components?

A

An input form element whose value is controlled by React

19
Q

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

A

The onChange and value props

20
Q

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

A

.map()

21
Q

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

A

listElement.id

22
Q

When does React call a component’s componentDidMount method?

A

Right after the render() method when the component is first instantiated

23
Q

Name three React.Component lifecycle methods

A

constructor(), render(), componentDidMount(), componentDidUpdate()

24
Q

How do you pass data to a child component?

A

By passing it in a prop