React Flashcards

1
Q

What is React?

A

a front end js framework

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

What is a React element?

A

an html element created by react

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

What is JSX?

A

Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, …children) function. The JSX code:

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

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

A

Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.

For example, both of the imports are necessary in this code, even though React and CustomButton are not directly referenced from JavaScript:

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

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

A

babel loader with jsx plugin

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

What is a React component?

A

class that returns a react element

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

How do you mount a component to the DOM?

A

ReactDOM.render()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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. Furthermore, props data is read-only, which means that data coming from the parent should not be changed by child components.

object argument with data

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

How do you pass props to a component?

A

When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object. We call this object “props”.

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

How do you write JavaScript expressions in JSX?

A

wrap it in curly braces

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

How do you create “class” component in React?

A

class keyword, name, render method

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

How do you access props in a class component?

A

this keyword

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

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

A

map()

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

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

A

an id value from the data model

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

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

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

Name three React.Component lifecycle methods.

A

These methods are called in the following order when an instance of a component is being created and inserted into the DOM:

constructor()
static getDerivedStateFromProps()
render()
componentDidMount()
componentDidUpdate()
componentDidUnmount()
17
Q

How do you pass data to a child component?

A

props