React Flashcards

1
Q

What is React?

A

React is a JavaScript library/framework 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, describes what you want the dom to look like

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)

Is to mount an element or component, only call it once

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

What is JSX?

A

Javascript syntax extension

JSX is a syntax extension to JavaScript that 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

Because the React library must be in scope from your JSX code. It is not used explicitly but the compiler (Babel) uses it when converting JSX to React.createElement( )

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

By installing webpack, webpack-cli, babel-loader, @babel/core, @babel/plugin-transform-react-jsx to your packge.json devDependencies

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

What is a React component?

A

Components are like JavaScript functions.

They accept 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
The simplest way to define a component is to write a JavaScript function. You can also use an ES6 class to define a component.
Components have to start with a Capital letter
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

Using ReactDOM.render( ) method - use the function name as the type

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

How do you create “class” component in React?

A
Begin with the class keyword followed by the className followed by extends React.Component 
then inside the class body, must define the render( ) method which returns the react element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you access props in a class component?

A

Use this to access props property of the this object in a class component.

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

What is the purpose of state in React?

A

When the state object changes, the component re-renders depending on the state
So the component can render different things depending on the state
State can change over time

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

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

A

Pass event handlers and other functions as props to child components:

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