react Flashcards

1
Q

What is React?

A

javascript library for building user interfaces (UIs)

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

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 the render method

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

What is JSX?

A

syntax extension

  • commonly wrapped in parentheses
  • multiple lines for readability
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

Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your 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

Babel compiles JSX down to React.createElement() calls

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

What is a React component?

A
  • like javascript functions
  • accept parameters called “props”
  • return react elements
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

you can define a component either through a function or a es6 class

function component:
use the function keyword followed by the component with the first character capitalized (components starting with a lowercase character are treated as DOM tags
  • note: a component function accepts a “props” (parameters) object argument
class component:
use the keyword class followed by the component name capitalize followed by the extends keyword and the component property of the react object
  • note: the render method is obviously defined inside the class component code block
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

specify the component in the render method of the reactdom object

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 technically properties of an object passed a parameter/argument to a component function

they are read-only

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

in component function definitions, we just pass it as a parameter/argument with the keyword “props”

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

use brackets around the javascript expressions

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:
use the keyword class followed by the component name capitalize followed by the extends keyword and the component property of the react object
  • note: the render method is obviously defined inside the class component code block
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 the this object

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

a value at the point of time of the component

privately and fully controlled by the component

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

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

A

as a prop(?)

17
Q

why use an anonymous function in a setState method rather than an object?

A

React may batch multiple setState() calls into a single update for performance

and hence: Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state

use a second form of setState() that accepts a function rather than an object

18
Q

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

A

map

19
Q

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

A

id

20
Q

What are controlled components?

A

element controlled by react

21
Q

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

A

value and onchange prop

22
Q

When does React call a component’s componentDidMount method?

A
  • invoked immediately after a component is mounted
  • after the constructor, render methods
  • need to handle the first empty render (i.e., “loading..”
23
Q

Name three React.Component lifecycle methods.

A

constructor, render, componentdidmount, componentdidupdate, componentwillunmount

24
Q

How do you pass data to a child component?

A

props