React Flashcards

1
Q

What is React?

A

A JavaScript library for creating 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 that describes what the DOM should look like

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

Keep in mind React takes over the whole DOM

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

What is JSX?

A

A syntax extension used in JavaScript, JSX produces React “elements”

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 will be called into React.createElement and therefore must be in scope

<h1></h1>

in React actually means -> React.createElement

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

Using babel-loader and the @babel/plugin-transform-react-jsx plugin

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

What is a React component?

A

Similar to JavaScript functions, they accept inputs called “props” and return React elements describing what should appear on the 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
function FunctionName(props) {
   return elementChildrenContent, {props.name};
}

props is optional

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.createRoot(document.getElementById(‘root’));

root.render(element);

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

What are props in React?

A

A JavaScript object

Children and attributes gathered into this object

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

’ < componentName propName = propValue / >’

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

Surround it with 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 ClassName extends React.Component {
   render( ) {
      return ' < React element type > ' React children 
      { this.props.name } '  ' ;
   }
}
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

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

How does extends work?

A

Used in class declarations or expressions that creates a child class of another class

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

What is the syntax for extends?

A

class ChildClass extends ParentClass

17
Q

How does super work?

A

Used to access and call functions from an object’s parent

18
Q

What is the syntax for super?

A

super( [ arguments ] );

super.functionOnParent( [ arguments ] );

19
Q

What is the purpose of state in React?

A

Represents the current status of the component

Keeps track of values that change over time

20
Q

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

A

As props to child components

21
Q

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

A

Map( )

22
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, typically an ID

23
Q

What are controlled components?

A

A form element whose value is controlled by React

24
Q

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

A

The result of the constructor’s method that controls the mutable state and the value

25
Q

When does React call a component’s componentDidMount method?

A

Immediately after a component is mounted (inserted into the tree).
- Initialization that requires DOM nodes should go here

Constructor occurs 1 time, render occurs, and then componentDidMount occurs once after one successful render occurs

Examples of this could be:
- A subscription setup

26
Q

Name three React.Component lifecycle methods.

A

constructor( )
render ( )
componentDidMount( )

27
Q

How do you pass data to a child component?

A

Pass a prop

28
Q

What is the component lifecycle?

A

The process in which a component runs its code

  1. Constructor is ran first and only once in the component lifecycle
  2. Render method gets called with initial state and its props being passed,
  3. componentDidMount method (optional) gets called after first successful render
  4. Event listeners and set states occur
  5. Render method runs again
  6. componentDidUpdate method gets called after every render
  7. componentWillUnmount is used when DOM elements are to be removed (example view swapping)