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

React elements are 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

ReactDOM.render(element, container, [callback]);

breakdown:
const reactH1Element = React.createElement(
  'h1',
  null,
  'Hello, React!'
);

ReactDOM.render(reactH1Element, document.querySelector(‘#root’));

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

What is Babel?

A

Babel is a JS complier; it is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments

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

What is a Plug-in?

A

a software component that adds a specific feature to an existing computer program.

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

What is a Webpack loader?

A

Loaders are transformations that are applied to the source code of a module.

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

How can you make Babel and Webpack work together?

A

install babel-loader and babel plug-ins as dependencies

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

What is JSX?

A

it provides the syntactic sugar for React.createElement(component,props,children) function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

You can have a Babel Loader with the react plugin

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

What is a React component?

A

Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

they are like JS functions; they accept arbitrary inputs (called “props”) and return React elements.

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

How do you define a function component in React?

A

Write a javascript function that returns jsx element.

ex: 
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you mount a component to the DOM?

A

ReactDOM.render(element, container)

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

What are props in React?

A

they are objects that hold properties of declared key/value pairs

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

How do you pass props to a component?

A

ComponentName (props)

When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object.

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

How do you write JavaScript expressions in JSX?

A

surrounding the expressions in curly braces

17
Q

How do you create “class” component in React?

A
class className extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
18
Q

How do you access props in a class component?

A

this.props

19
Q

What is the purpose of state in React?

A

to keep track of values that changes over time.

20
Q

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

A

pass a property in the render method.

21
Q

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

A

Array.map()

22
Q

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

A

string value – anything unique such as an id

23
Q

What are controlled components?

A

An input form element whose value is controlled by React.

-accepts its current value as a prop, as well as a callback to change that value.

24
Q

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

A

value, onChange

25
Q

When does React call a component’s componentDidMount method?

A

after render();

These methods are called in the following order when an instance of a component is being created and inserted into the DOM:

constructor()
static getDerivedStateFromProps()
render()
componentDidMount()

26
Q

Name three React.Component lifecycle methods.

A

componentDidMount()
componentDidUpdate()
componentWillUnmount()

27
Q

How do you pass data to a child component?

A

using props (adding key and values to the props object of the component)