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.

Complex lifecycle logic

Complex lifecycle logic

Hello and welcome back. In this video, we will discuss the complex lifecycle logic. When we are using the class components, you often need to have coordinate multiple lifecycle methods. For example, if we want to fetch data, set some timers or do a cleanup function or whether it's a case of updating the state using props. We always have to use some of the lifecycle method. This leads to a complex hard-to-follow logic. Let's see an example of complex lifecycle hooks usage to better understand it. Over here, you have a class-based component which is using multiple lifecycle methods. At first, you have this componentDidMount lifecycle method which is actually calling a FetchUser function based on the userId props. After that, we have the componentDidUpdate lifecycle method which is receiving some props And based on the user id, it's again fetching the user. After that, we have a cleanup function in component will unmount that when the component has to unmount on the screen, we have to…

Contents