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

A plain javascript elements that describes what a DOM element should look like. Simpler than DOM elements

Something that the framework stores in memory. References that so that the DOM knows what to do

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is JSX?

A

A syntax extension to JavaScript.

JSX produces 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

Needed so JSX can be converted to React code

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
webpack
webpack-cli
babel-loader (makes webpack and babel work together)
@babel/core
@babel/plugin-transform-react-jsx

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

What is a React component?

A

A function or a class

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

-Write a JS function with optional props parameter. Function component name must be capitalized
- has to return React element

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
  1. Query the dom for the element that will serve as the container
  2. Create a root by passing the container through the createRoot method of the reactDOM object
  3. call the render method of the root object and pass through the React element

ex)

const container = document.querySelector(‘#root’);
const root = ReactDOM.createRoot(container);
root.render(;

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

What are props in React?

A

An object
Arbitrary inputs accepted by React components.

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 an argument

When you create your React element, you specify what you want to pass as key value pairs

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

put them in curly braces
{prop}

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 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
14
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
15
Q

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

A

Array.map()

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

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

A

The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:

17
Q

When does React call a component’s componentDidMount method?

A

It’s invoked immediately after a component is mounted (inserted into the tree).
After the first successful render

18
Q

Name three React.Component lifecycle methods.

A

1) componentDidMount
2) componentDidUpdate
3)Unmounting

constructor
render

19
Q

How do you pass data to a child component?

A

props