Appendix
Appendix A – How many component types does React support?
In the published React documentation, it supports two component types. One is a function component, and another one is a class component. React supported the class component from the beginning:
class ClassComponent extends React.Component { render() { const { name } = this.props; return <h1>Hello, { name }</h1>; } }
Although the render
function of a class component looks quite similar to what a function component returns and, most of the time, we can convert them in between, the class and function components are treated differently inside the React update process. Therefore, this book intentionally avoids mentioning the class component so as not to confuse any newcomer to React.
In general, a function component can be written shorter and simpler, and it's also easier in terms of development and testing because it has plain...