React Flashcards

1
Q

What is React?

A

JavaScript library for creating 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

plain objects that contain information needed to turn it into a 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

Using ReactDOM.render(element, container [, callback])

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

What is JSX?

A

It is syntactic sugar for creating React elements

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

It is just syntactic sugar for createElement method of the React object

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

Install both webpack and babel/babel-loader. Use babel plug-in for converting JSX

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

What is a React component?

A

Essentially just a function that returns 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

Normal function definition, but React components have first letter capitalized

Can also define a component via class:
class ComponentFunction 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
9
Q

How do you mount a component to the DOM?

A

Using the ReactDOM.render( ) method

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

What are props in React?

A

Props are essentially objects that get passed into the createElement method that get attached to the React element in a way that mimics HTML attributes

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

How do you pass props to a component?

A

as property=value pairs within the JSX syntax

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

How do you write JavaScript expressions in JSX?

A

can embed JS expressions by enclosing them in squiggly brackets { }

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

How do you create “class” component in React?

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

How do you access props in a class component?

A

Through this.props

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

What is the purpose of state in React?

A

an object that is maintained within the component that indicate its current state

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

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

A

assign them as a prop with the value of a callback function

17
Q

What are controlled components?

A

Components that control both its state and a form element’s values.

18
Q

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

A

value=this.state.value

onChange=handleChange

19
Q

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

A

array.prototype.map( )

20
Q

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

A

the data’s ID or any other unique identifier

can be unique only among its siblings

21
Q

When does React call a component’s componentDidMount method?

A

after the render( ) method call ONLY if it’s the first iteration

constructor > render > componentDidMount

22
Q

Name three React.Component lifecycle methods

A
constructor
render
componentDidMount
componentWillUnmount
componentDidUpdate
23
Q

How do you pass data to a child component?

A

through props