React.js Flashcards

1
Q

What is React?

A

A JavaScript library for creating UI.

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

What is a React element?

A

It describes JavaScript objects that are seen on a webpage.

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 the .createRoot() method of the ReactDom object with the element as its argument.

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

What is Babel?

A

Babel is a toolchain used to convert JavaScript ES6 or later into a backwards compatible version.

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

What is a Plug-in?

A

A plug-in is a software component (customization) that adds a specific feature to a program.

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

What is a Webpack loader?

A

A Webpack loader pre-processes files as they are imported. Examples include transforming files from a different language to JavaScript.

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

The babel-loader package is needed. Webpack bundles modules and Babel transforms code by applying plugins which Webpack will bundle.

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

What is JSX?

A

A syntax extension of JavaScript that is used be compiled into real JavaScript.

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

Although the React object is not visibly used, JSX is compiled into a React element.

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

By using the Babel Loader and telling it to use the react-jsx plugin to convert JSX to JavaScript.

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

What is a React component?

A

A reusable JavaScript function or class that returns React elements represent a section of UI.

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

The function keyword followed by a
name with a capitalized first letter, parameter list, and function code block.

Inside the function code block is a React object being returned from the function.

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

By creating a root and calling the .render() method of the root object with an argument of one or more react elements.

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

What are props in React?

A

Props (short for Properties) are arbitrary inputs that describe a React element or object.

Props is an object datatype.

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

By adding a prop name and its value to a React element. If the prop value is not a string, then a JavaScript expression can be used instead.

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

By surrounding it in curly braces.

17
Q

How do you create “class” component in React?

A

The ‘class’ keyword followed by the component’s name, the ‘extends’ keyword, the Component property of the React object, and the curly braces for the class body.

Inside the class body, and prototype method named render is defined with no parameters followed by curly braces for the function code block.

Inside the function code block is an expression being returned from the prototype method.

18
Q

How do you access props in a class component?

A

By using the ‘props’ property of ‘this’ object inside a JavaScript expression.

19
Q

What is the purpose of state in React?

A

To hold information about an element or component until an event take place. (???)

A data model of values that change over time.

20
Q

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

A

By calling the event handler property of ‘this’ object as a JavaScript expression. (???)

As a prop of a React element.

21
Q

What are controlled components?

A

An input form element whose values are controlled by React.

22
Q

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

A

The onChange and value props.

23
Q

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

A

The .map() method.

24
Q

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

A

A unique identifier as a string.

25
Q

When does React call a component’s componentDidMount method?

A

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

26
Q

Name three React.Component lifecycle methods.

A

constructor(), componentDidMount(), and render().

27
Q

How do you pass data to a child component?

A

By rendering the child component and passing in the parent component’s state as a prop.