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

An Object

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(Element, Container[, callback])

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.

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

Because JSX compiles into calls to React.createElement, the React library must also be in scope from the JSX 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 the babel-loader as a devDependency.

add the plugin @babel/plugin-transform-react-jsx in the

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

What is a React component?

A

It is a “function” or “class” that accepts arbitrary inputs (called props) and return React elements describing what should appear on the screen.

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 keyword

Name (must start with capitalized letter)

(props)

return JSX

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

Assign the return of the component to a variable.

Call the render method of the ReactDom object

Pass the variable containing the component as the first argument in the render method then query the DOM for the element you are mounting the component to.

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

What are props in React?

A

Props is an object
When react sees an element representing a user defined component, it passes JSX attributes and children to this component as a single object.

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

Pass it as an argument when the component is created?

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

Surround it with curly braces.

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

How do you create a “class” component in React?

A

class keyword followed by the name of the component followed by extends. Then call the Component method of the React object followed by curly braces. Define the render() method followed by opening curling braces and return the JSX.

There are other options we haven’t gone over yet.

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 is the purpose of state in React?

A

To store property values that belong to components. When the state changes the component re-renders.

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

add the corresponding prop/value pair to the element being “created”

The prop name has to start with on and must be in camelCase.

17
Q

What are controlled components?

A

When the React component that renders a form also controls what happens in that form at the same time.

18
Q

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

A

value prop and the on change prop.

19
Q

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

A

Map()

20
Q

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

A

A unique ID between the siblings, preferably not the index.