React Components
Now let's dig into how these components work. There are several different ways to declare a component in React. You even have the choice to use JSX or not. This book will focus on creating components with function expressions, but we'll go over a few other patterns, so you'll know them when you see them.
Class Components
This style of component follows a classical (that is, relating to the programming concept of classes) pattern of component declaration. Many older examples will use class components, but they have fallen largely out of fashion due to being more verbose than other patterns. To create a class component, we import the Component
class from React and extend it while creating our own class:
import React, { Component } from 'react'; interface Comp1Props { text: string; } export default class Comp1 extends Component<Comp1Props> { render() { const { text } = this.props;...