React.js Flashcards

1
Q

What is React?

A

React is 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

A React Element is what gets returned from components.

It’s an object that virtually describes the DOM nodes that a component represents.

An element is a plain object describing a component instance or DOM node and its desired properties.

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

By using ReactDOM.render

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

What is JSX?

A

JSX is an XML-like syntax extension to ECMAScript w/o any defined semantics.

It is called JSX, and it is a syntax extension to JavaScript.
Used to write HTML tags inside JavaScript.

JSX is an XML/HTML-like syntax used by React that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript/React code

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

JSX works with React.render() or createElement(); belongs to React

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

Use babel loader and install the babel-plugin that transforms 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

Conceptually, components are like JavaScript functions.

Components let you split the UI into independent, reusable pieces.

Think about each piece in isolation.

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 Name (props) {
return (rendered React elements)
}
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

By using ReactDOM.render on the 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

They are objects; Props stand for properties; used to pass data between React components

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

’ ‘ if it’s a string and { } if not.

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

put them in 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
keyword class name keyword extends react.component {
render() {
return the react elements
}
}
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 keep track of values that will change over time

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
Pass the event handler to the React element’s prop
// pass in a function as an event handler
17
Q

What are controlled components?

A

a component whose input’s value is always driven by the React state. you can now pass the value to other UI elements too, or reset it from other event handlers.

18
Q

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

A

Value and onChange

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

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:

21
Q

When does React call a component’s componentDidMount method?

A

immediately after a component is mounted (inserted into the tree).

22
Q

Name three React.Component lifecycle methods.

A

constructor, render, componentDidMount, didunmount, update, error handling

23
Q

How do you pass data to a child component?

A

through props. (passing a prop as a javascript expression