From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Class components

Class components

Hi, in this video we are going to discuss class-based components. As you know that class-based components were introduced before hooks. We can define a class-based component by creating a class which will be inheriting from React.Component. It contains a state object where all the state of the component is going to go. And it has lifecycle methods instead of hooks. That's how a simple class-based component looks like. It can receive props. It has a state object where we define all the state of that component. And then we have a render function. Let's discuss lifecycle methods of class-based components in more detail. There are a number of lifecycle methods available which we can utilize in a class-based component to do the thing we want. There is a componentDidMount lifecycle method which runs after the very first render. Then we have componentDidUpdate function which runs after we have made any changes to the state. Then we have a componentWillUnmount. This is an area which gets…

Contents