React Flashcards

1
Q

What goes at the top of every React component?

A

import React from ‘react’;

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

What is the basic format for creating a class-based component?

A
class MyComponent extends React.Component {
  render() {
    return <h1>I am a component</h1>;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the basic format for creating a functional component?

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

Do React component names always need to start with capital letters?

A

Yes!

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

What does it mean that React components are pure?

A

It means that they never modify their props. Such functions are called “pure” because they do not attempt to change their inputs, and always return the same result for the same inputs.

All React components must act like pure functions with respect to their props.

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

What is the root DOM node in React?

A

It is the element in your DOM that you designate as the container for your React app. We call this a “root” DOM node because everything inside it will be managed by React DOM. Applications built with just React usually have a single root DOM node.

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

How do you render a React element into your root DOM node?

A

To render a React element into a root DOM node, pass both to ReactDOM.render():

const element = <h1>Hello, world</h1>;
ReactDOM.render(element, document.getElementById('root'));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the one required method in a React class component?

A

The render() method is the only required method in a class component, which is used to render DOM nodes. A class component must include render(), and the return can only return one parent element.

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