React.js 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

An object; An element describes what you want to see on screen. Unlike a DOM element, React elements are plain objects, and are cheap to create.

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

With the render method of the ReactDOM object;

ReactDOM.render(element, container[, callback]

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

What is JSX?

A

A syntax extension for JavaScript used with react to describe what the UI should look like.

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 JSX produces React “elements”.

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 adding the @babel/plugin-transform-react-jsx, babel-loader too.

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

What is a React component?

A

A React component is conceptually like a JavaScript function. They accept arbitrary inputs called (“props”) and return React elements describing what should appear on 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

You can write a JavaScript function accepting “props” as a single object parameter and returning a React element;
You can also use ES6 classes.

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

With the render method of the ReactDOM object.
(first argument is a react element, using the function name as the type. Second is where you would like it to be mounted.)

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 single object arguments which contain 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

By passing the props object as a parameter in the component definition, and then accessing it via JavaScript Expressions; ( within the react Element )

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

By enclosing the JavaScript expression in curly braces. Then you can add in whatever expression you want, (besides if/or)

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 ‘reactElement’
({this.props.text})

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

with ‘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

So we can change how an element renders over time. (vs having to create another element each 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

As a prop, the event name is ‘on’ + ‘eventNameInCamelCase’

17
Q

What are controlled components?

A

Input form elements whose values are controlled by React to decide what happens on subsequent user input.

18
Q

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

A

value, onChange

19
Q

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

A

The map method.

20
Q

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

A

A string that uniquely identifies a list item among its siblings.