React 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 gets returned from React components, it is an object that virtually describes the DOM nodes a component represents.

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, target)

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

What is JSX?

A

JSX is an extension of JavaScript syntax used by React to allow for HTML-like text to exist in JavaScript 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

Because React elements written in JSX are syntactic sugar for React.createElement calls.

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

Ensure that @babel/plugin-transform-react-jsx is listed as a Babel plugin in webpack.config.js

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

What is a React component?

A

React components are reusable pieces of code that accept a props argument and return React elements.

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 Comp(props) { return <h1>example</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

ReactDOM.render(reactElement, domTarget);

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

What are props in React?

A

Props are properties that get passed into React components and represent the properties of a React element.

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

Specify them using key=”value” pairs in the opening tag of a React element representing a user-defined component.

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

class ComponentName extends React.Component { render() { return } }

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

state is an object in a React component that keeps track of the state of a component and can be updated upon certain events.

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

Specify an event handler as the value of an OnEvent prop in a React element tag.

17
Q

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

A

.map()

18
Q

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

A

A unique string for each item in the list.

19
Q

What are controlled components?

A

An input form element whose value is controlled by the React component’s state, making it the “single source of truth”.

20
Q

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

A

value={this.state.value} and onChange={this.eventHandler}

21
Q

When does React call a component’s componentDidMount method?

A

componentDidMount is called after constructor() and render()

22
Q

Name three React.Component lifecycle methods.

A

constructor, render, componentDidMount, componentDidUpdate, componentWillUnmount

23
Q

How do you pass data to a child component?

A

Through the props.