React Flashcards

1
Q

What is React?

A

React is a free and open-source front-end JavaScript library for building user interfaces based on UI components.

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

What is a React element?

A

A React Element is what gets returned from components. It’s an object that virtually describes the DOM nodes that a component represents. With a function component, this element is the object that the function returns. With a class component, the element is the object that the component’s render function returns.

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( )

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

what is JSX?

A

Its a syntax extension to JavaScript.

JSX stands for JavaScript XML. JSX allows us to write HTML in React.

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

If you give some JSX to Babel, you will see that JSX is just sugar for React. createElement calls. This is why we need to import React if we use JSX.

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-loader?

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 independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. Components come in two types, Class components and Function components, in this tutorial we will concentrate on Function components.

function or class and returns a react element. it can be an element tree.

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
So a Functional Component in React:
is a JavaScript/ES6 function.
must return a React element (JSX)
always starts with a capital letter (naming convention)
takes props as a parameter if necessary.
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

ReactDOM.render( react-element, container)

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

What are props in React?

A

React has a special object called a prop (stands for property) which we use to transport data 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

To the component as an argument

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

To write a JavaScript expression within JSX you will have to surround the JavaScript code in { } brackets. In the React/JSX code below I am mixing JavaScript expressions (e.g., 2+2 ), surround by { } among the JSX that will eventually get evaluated by JavaScript.

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

Creating a class component is pretty simple; just define a class that extends Component and has a render function.

render() purpose is to return the react element. thats it.

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

using ‘this’ keyword

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

State is a plain JavaScript object used by React to represent an information about the component’s current situation. It’s managed in the component (just like any variable declared in a function)

keep track of values which change over time

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

pass into the props value

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

unique value that represents each object

19
Q

What are controlled components?

A

A controlled component is a component that renders form elements and controls them by keeping the form data in the component’s state. In a controlled component, the form element’s data is handled by the React component (not DOM) and kept in the component’s state.

20
Q

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

A

value and onChange

21
Q

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

happens the first time after the first successful render.

22
Q

Name three React.Component lifecycle methods.

A

Mounting, Updating, Unmounting, render, componentdidmount etc….

23
Q

How do you pass data to a child component?

A

pass a prop