React Flashcards
What goes at the top of every React component?
import React from ‘react’;
What is the basic format for creating a class-based component?
class MyComponent extends React.Component { render() { return <h1>I am a component</h1>; } }
What is the basic format for creating a functional component?
function MyComponent(props) { return <h1>Hello, {props.name}</h1>; }
Do React component names always need to start with capital letters?
Yes!
What does it mean that React components are pure?
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.
What is the root DOM node in React?
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 do you render a React element into your root DOM node?
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'));
What is the one required method in a React class component?
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.