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

Object but it contains a typeof key that has a value of symbol(react.element)

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

Call the render method of the root object.
root.render( ).

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

What is JSX?

A

it is a syntax extension to JavaScript, that allows us to describe React’s object tree using a syntax that resembles that of an HTML template.

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

We need react for when the babel-loader translates the JSX it changes the syntax to React.createElement, and if React is not defined / imported it will throw an error.

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 plugin-transform-react-jsx
devDependencies - @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

Reusable pieces of code / Functions that return a React element to be rendered to the page.

Components are like JavaScript functions, They accept inputs (called props) and they 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

The simplest way to define it is with a JavaScript Function.
Name of the function component has to start with an Uppercased letter

function Welcome(props) {
return <h1>Hello, {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

make a user defined component.
create a react element containing component name
root.render(react element)

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

What are props in React?

A

objects that gets passed from one component to another

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

key value pairs that look like html attributes

< ComponentName name=”Alvaro” color=”blue”.
^ ^ ^ ^

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 any JavaScript expression with curly braces.

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

define a class that extends React.Component and has a render function.

Component Name must start with an uppercase.
Component has to include extends React.Component.
Component also requires a render( ) method.

class ComponentName extends React.Component {
render( ) {
return (
<h1> { 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

The This Object in front of the props object.

<h1>Hello, {this.props.name}</h1>

this.props is the object which contains the Attributes which we have passed to the parent component.

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

keep track of values that change overtime.

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

we pass it as a prop.
if the event is a click it would be onClick as a prop

17
Q

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

A

Map Method

18
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:
Use the item index as a key as a last resort:

19
Q

What are controlled components?

A

An input form element whose value is controlled by React

An input form element whose value is controlled by React in this way is called a “controlled component”.

20
Q

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

A

value and onChange props