What are React Components?
To define a React component class, you need to extend
Component, this creates inheritance to React’s Component and gives us access React Component’s functions (such as the required render() function).
The only method in React Component we must define in a class component is render(). The other methods (ex componentDidMount() shown below) are optional. Render is invoked whenever the component needs to update and a component is updated whenever there is a change in the components state or props .
- Class components are stateful, contain logic and have lifecycle functions
- Function components are stateless (unless React Hooks are used), their only job is to display data and they don’t have access to lifecycle functions