- Podcasts
- ReactJS Developers Podcast
- React Lifecycle Methods Explained | Mastering the useEffect Hook
React Lifecycle Methods Explained | Mastering the useEffect Hook
ReactJS Developers Podcast
- December 3, 2026
- 40 min
- Episode 19
About this episodeUnderstanding the React component lifecycle is essential for building efficient and interactive React applications. In this episode, we…
- Understanding the React component lifecycle.
- The three lifecycle phases: mounting, updating, and unmounting.
- What the useEffect Hook does and when to use it.
- Running effects after a component renders.
- Understanding the dependency array.
- Running effects only when specific values change.
- Using cleanup functions to prevent unwanted side effects.
- Common useEffect mistakes and best practices.
- Understanding how useEffect relates to class component lifecycle methods.
- Beginners learning React JS and Hooks.
- Frontend developers working with functional components.
- JavaScript developers transitioning to modern React.
- Developers who want to understand side effects and component behaviour
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
React Lifecycle Methods Explained | Mastering the useEffect Hook
Till now, we have learned so much that we are able to build our applications and projects. And we have also built many projects. But as a developer, your only job is not to build applications or web applications. You have to pay attention to performance optimizations too. It is also your job to improve performance. So how can we improve performance? How can we optimize the performance of our application? We are going to see all those things now. And the next 3-4 topics or 3-4 lectures will be based on performance optimization. And the first video of our performance optimization is React Lifecycle Methods. You will not be able to optimize performance until you learn this. This is the most important thing. React Lifecycle Methods. Which we will learn quickly through code and will not discuss much on theory because there is nothing to do with theory here. We have to do it and see how we can optimize and what are the problems. It is very basic, react lifecycle method. If you watch any video, then in 15 to 20 minutes, it can be properly cleared. But there are some things that you have to understand, that you can make such mistakes. It is very important to understand the lifecycle. But along with that, it is also very important to understand what mistakes we make in the lifecycle. And all those things I will tell you now. Let's quickly come to the code. Here, the way we are organizing our code starting, as I said, I have made the folder structure of the wheat, here app.jsx is open and it is also running, you guys quickly install it, run the command, install the wheat, set the folder structure properly, and keep coding with me. Because until you do not code, you will not understand. All the performance things that I am telling you now, keep coding with me, only then you will understand. This was going wrong and we can improve in this way. So, let me show you that our app component is being run, which is this one. The first thing I will revise you is the useEffect. Because for now, the whole game is of useEffect. When does useEffect run? First, let me tell you this. So, you should get the answer quickly. You have done everything in a lot of depth till now. Okay, this revision is going on a little bit. After that, we will discuss the lifecycle method in continuation. All are based on useEffect. So, useEffect runs whenever your component is re-rendered or when your state changes. When state changes, re-render triggers in component and when re-render triggers, useEffect runs. So, I will make a state here. First of all, I will write CLG here. Re-render is done. I am not giving any dependency array. Look carefully. Here I have passed only one function. What is it taking? It is taking a function. and a function, and then dependency array. It is taking these two things. So, first of all, we have passed this function. Alright, where it is doing console, it has been re-rendered. And now if you come here and see, I open console by tying ctrl-shift and I also zoom a little here. So, it has been re-rendered. You can see it here. And it is coming twice because our strict mode is on. Remove strict mode from here. So, you will see this only once. Okay? You will understand it well. So, here, see, it has been re-rendered. So, useEffect is the first time, when the component is loaded, when the component is loaded, then, here, whatever you are doing in useEffect, you will see that. Okay? And when it is rendered, so, if you are changing something in the state, like, I make count and accept count here, using useState. Okay? And here, By default, it will be 0. And I will use this count here in H1 tag. Okay. This is just to make it look bigger. There is nothing else. And I will take a button here. Increment. And here I will quickly put onclick. And I will say set count. Set count. Count plus 1. That means keep increasing the count. And all these things are very basic. So, as I increment, re-render is still triggered. That means, when we change the state, re-render is triggered and useEffect is run. So, first thing is to load. After that, if we update something in the state, then our re-render is triggered. And if you change it in any state, then re-render will be triggered. Like, we had made one state here. Let's make one more here. And setData is equal to useState. And here we give tan. Okay. And... Let's take one more h1 here and render data here and take one more button and say decrement here and decrement the data. We are incrementing the count and decrementing the data. Set data and here we will do data-1. You know these little things. So, we come here and reload. See, re-render is triggered. Re-render is done basically. First time when component is loaded. Alright. Then if we are doing increment, then re-render is done. And if we are doing decrement, then re-render is done. That means whenever we change in state, in any state, it doesn't matter in which state you are changing. If any state is changing, then re-render is done. So, you have to keep all these things in mind. Now, let's come to life cycle. Okay. What does life cycle say? So, if you have given the react lifecycle and notes, you have to read it. I will read you a little bit above. Every react component goes through three main phases. All the components are there. In react, if you make any component, then there are three phases of everyone. First of all, mounting. Basically, component is loading, mounting and coming on screen. Component appears on screen. That is your mounting phase. After that, your updating phase. State and props changes. Whenever in state or props, listen carefully, in state or props, if change happens in state or props, then re-render trigger happens. And here you can say updating also, that update is happening. Whenever something changes in state, re-render trigger happens. That means update is happening, whole component. where you have used the state. Alright. Then there is unmounting. Component remove from UI. When component is removed or you shift from one component and come to another component. Suppose it is the first component. Or you are going from one page to another page. So your component is removed from one component and coming to the second component. So that is your unmount. So first of all, mount. After that, when you change the update in any state, a rerender trigger occurs and that update phase is running there. After that, unmounting. These are three phases. You have to understand these three phases. And on these three phases, react component properly makes you available to work on all three phases. You can do your work even if it is mounted, which is a use effect hook. You can perform your task even if it is updated, which you do through the use effect hook. You can perform your task even if it is unmounted, and this too you do through the use effect hook. Let's see how to do it. So, you are clear about the mounting. Whenever the mount happens, the use effect will run. As we were reloading here. So, the use effect has been run. The use effect has been run on the mount. I will write mounting here. So, it is running on the mount. Let's reload. See, it is running on the mount. Ok, there is no issue. For update, we will put a dependency array here. Because the dependency array is empty, it will run only when it is mounted. It will not run if someone changes the state. So if any state changes, it will not run. This means that it is not giving any reaction on updation. If you want to perform something on updation, you can tell in this dependency array which state you want to perform the task on. You can make more than one use effect, like I made this for mounting. I make one especially for updation. Use effect and here In this way I will put data in the dependency array. And I will do CLG here. Data changed. Ok. And if the data is changed, then you can see it here. So there is no need to show it here again. So now tell me when this one will run. So the first time it will run on mounting. When it is being mounted. So let's come here and see. Let's reload. So see here the mounting is done. And the data is changed and run. When it is being mounted for the first time. After that, if you are clicking on increment, then You can't see any task here, nothing is happening. But as soon as we click on the decrement, because the data is changing and we have put the data in the dependency array. So here you can see that the data has changed. Because we have put only data in the dependency array. If we put count in the dependency array. If we put count with data in the dependency array. So if any change happens between count and data, then you will see this data changing. You can see the data is changing. You can also do it separately. For example, if you want it separately for the count, then you can make a separate use effect for the count here. So, when the count will be updated, then only it will work, it will change basically. So here I remove it and do it. Count changed. OK. Let's reload. So look at this. The mounting data changed when reloading. the count changed. All three have been run once. It runs when it is mounted. After that, when we click on increment, see the COUNTCHANGED use effect is running. And as soon as we click on decrement, the data changed use effect is running. So, in this way you can tell that in the update, in the update phase, what you have to react on changing to which state or what kind of task you have to perform, what logic you have to do. Okay, so we understood mounting, we understood updating, now we understand unmounting and this is very important for you. Updating and mounting you were already knowing to some extent, but I had not told you about unmounting before, so now you have to understand carefully how unmounting is working and how we can perform clean up etc. So here I will make this assets folder and in SRC I will make a component folder. Components. Ok. And in components I will make a component alpha.jsx rafc. This is our alpha component. Very good. And I will put all this in notes by pressing ctrl c. New folder, notes. Ok. mounting and updating.jsx and you will get all of this here and I will remove it from here for the time being ok and remove this also from here and for the time being we are running alpha ok alpha now look carefully look carefully I am making use effect by coming inside alpha where am I making in alpha use effect And I am not giving any dependency array in this. And here I am doing CLG. Rerendered. Okay. And I am changing the state here. I am making a button. Button. And what will I do in the button? Let's make a button named increment. And here on click. Set count. Count plus one. Okay. And let's come here. Let's reload. Where have I re-rendered? Where? In the child component, which is the alpha component we have used. And where are we changing the state? Here. This count set count and that too we are changing in the parent. So you know this much that whenever we change something, there will be a re-render trigger in the parent component. But will the child component also be re-rendered? If the child component is re-rendered, then you should run this use effect which is re-rendered. Is this true? Will it run? Let's see. So here as I am incrementing, see it is being re-rendered. That means parent component is also being re-rendered. But all the other components that we have used in it are also being re-rendered. Okay, you have to keep this in mind. In future, we will see all these things to improve. If your child component is very big and there is no dependency on the parent, then why should that also be re-rendered? We don't have to re-render that. Just in which we are using props, in which we are sending data, parent to child, Re-render trigger should be in that only. Because change is in that only. It is not in other child components. So what is the need of re-render trigger? So this is what we are going to see next. So understand this carefully. Whenever we are changing something, child component, where there is no dependency from parent, still re-render is happening. Is it happening? Yes, exactly it is happening. We understand this. And this is related to the next topic. So don't pay much attention. Just understand that re-render trigger is happening. Alright, now we need to understand unmounting, right? We need to understand unmounting. So what I will do here, instead of data, I will make a toggle state. Toggle and here set toggle. Unmounting is very important for cleanup etc. That when component is unmounting, then you perform the cleanup etc. task. So in use state, I will put false. Okay. And here using toggle state, I will show alpha. I will say if toggle is true, toggle is true, then only you have to show alpha component otherwise don't show it. Okay. Do it like this directly. If toggle is true then only we have to show alpha. Then only we have to render alpha component. So will alpha component be rendered now? Absolutely not. Because toggle is false. You know this much. You have this much idea. And here I will use toggle instead of increment. Okay. And here set toggle true or not of toggle, basically click on it and it should be true or false if it is already true, so now look carefully, what I have re-rendered in the use effect, that is the alpha component, we have written a use effect in the alpha component, so now Component is not here. Component mount is not done yet. So, it is re-rendered. You can't even see it. We have put use effect in alpha. Okay. So, as soon as we toggle, as soon as component is mounted, now you will understand all three here. Mount, update and unmount. So, as soon as component is mounted, you have this run. That means, you are able to perform your logic when it is mounted. Okay. Are you able to do it when it is updated? So, yes, you can do it when it is updated. You can do it in the same way here. Const count SetCount is equal to useState and 0. And here in alpha itself, we use the count variable. And here we also give a button named increment. Alright. And here in this way, we will also put onClick. And at the same time, we will also do setCount quickly. Count plus 1. Okay. Reload and see that the component is not visible. As soon as you click on the toggle, the alpha component has come and as soon as you click on increment, the rerender is triggered. And if we put the dependency array here, then it will be rendered only once, that means it will be mounted. When this component is mounted, then you will see the rerendered app because we have written it in the console. There is no change in the increment and change in the state. But if I put it in the count dependency array, then you will see that as soon as it is toggled, the first time the rerendered is coming and as soon as we change it in the state, it is also coming. But now we will change it only in the count state, only then this use effect will run. Alright, that means we are able to perform our logic in the updation phase. Now it is time to perform some logic in the unmount phase. For example, when toggled, here it is re-rendered. Alright, re-render or just say mounting. Mounting is better. Mounting. So as soon as we toggle, mounting, mount is done. After that, when toggled again, the cleanup task should also be performed. If you have done a lot of dirt in the component, then clean up should also be performed. How can you do that? You can do that very easily. In this useEffect, when you change in count, then the clean up logic will also work. So here you can return a function. I will tell you that everything will be clear. You can return a function and here you can perform the cleanup task. For now, I will write unmounting is happening. So wherever unmounting is happening, you can perform the cleanup task or whatever logic you want to perform. So reload and toggle here. See it is mounted and as soon as we change it to the state, unmounting is happening. So understand this carefully. that we don't have to run unmounting when we change the state. We have to clean up when the component is unmounted. We don't want to run the use effect when the state changes. So, what will we do here? We will not apply it in the updation. We will create a new use effect. And in this, we will keep the dependency array empty. That means, this component will run only when it is mounted and unmounted. while mounting and while unmounting. If we do CLG here, mounting, it will run while mounting, this is the logic, what we have written here, console.log, and if we give a return function here, so now this one will run only when unmounting will happen. Now look carefully, as soon as we toggle, see the mounting, the second mounting is coming from here, the first mounting is coming from here, so I remove this. I will remove this. So, I clicked here. See, mounting happened. And nothing will happen if I click on increment because we have removed that use effect. We are toggling again. Unmounting. Okay. As soon as we toggled again, then only this function is running here. That means unmounting. That means while cleaning up, you can work like this. You are understanding, right? See here again. As soon as we toggled, this one is running. Mounting. Once the useEffect runs, this code runs. Only this code runs when unmounted. And if you give something in the dependency area, then when the state changes, it will work here and unmount again. So keep this in mind. If you are giving the dependency area empty, then you have to mount it to toggle. If it is unmounting, then you can perform the unmounting or cleanup task here. And if it is not that clear what to clean up, how to do it, then I will give you a nice and will explain it to you and it will be clear to you properly. Suppose I want to make a form pop-up here jsx form.jsx rafc and here we try to make a very simple form. We will take an input and in placeholder enter name and also make state here const name set name is equal to use state it is very simple only one input field is filled here and nothing else ok so set name here by putting on change on change we will get an event object from here and we will set e.target.value in set name e.target.value alright And we will link this name here. We will make it a controlled component. Okay. So, will this work for us? Let's see. CLG name. And let's do one thing. Okay, we have linked it. So, we will see it here. Okay. So, now we will in toggle, if toggle is true, then we will want to show this form instead of alpha. Okay. Form component. Let's remove this. Now you see carefully, as soon as I click on the toggle, the component of the form is coming to you and it is coming undefined because because here in the name, you don't have anything right now. If you put it empty here, nothing will come. As soon as I clicked on the toggle, which component is being mounted? The component of the form is being mounted. Have we done anything in the form component? Not at all. We just handle the input here. So as soon as I write something here, M A N A S. If I click on toggle again, will it be unmounted? Yes, unmounted. Will the data also be cleared? Not at all. You have to understand that the data is not being cleaned. You have not written any logic on unmounting. You have not written any logic on unmounting. But still you will feel that it has been cleaned, whereas it is not being cleaned. You have not done any cleanup task. As soon as I click on the toggle again, see here you have the component again, it has been mounted again and here you can see the whole state empty. So this will make you feel that the cleanup task has been done. But this is not the case. This is happening because when the component is being rendered again, then here this line is also running again and the empty value is being set in the state. But it doesn't mean that you have performed the task of cleanup or react can handle the cleanup itself. When you are doing something by linking local storage, session storage etc etc or by linking with the database itself, then you have to perform the task of cleanup. It's not like your state is empty directly. For example, I can show you an example in onChange. So, wait a little bit. I am doing setName in onChange. Along with that, let's correct some syntax here so that I can write something else here. So, we are doing setName here. Very good. Along with that, what will I do? I will do localStorage.setItem. I will put the name key and in the value I will put e.target.value. I am also setting it in local storage. Ok. Ok. So, what will happen here? Here we will get from local storage. local storage.getItem and in the key we will put the name. So, whenever the component will be mounted, it will be getting from the local storage. And whenever we are changing the input, it is getting from the local storage. So, there is no tension of flying. That the component will be mounted again, so the empty data will be set here. This is not at all. So, we keep console.log as it is and reload here. And as soon as we toggle, value prop on input should not be null. Considered using an empty string to clear the component or undefined for uncontrolled components. Alright. So, it is saying that the name you have given in value prop is getting null. So, you don't have to give null in value prop. Either you give undefined if you want to keep a controlled component or But we are getting null from local storage because we don't have anything in local storage. So to fix this, we can say that if you don't get anything in the get item, then set empty string instead of null. Set empty string. Now you will not get this error. Reload. Now component is not there. Let's mount component. We have toggled. Component is mounted. And now we will write manas. So minus is written here. It is also visible in the console. Along with that, it is also saved in local storage. Understand carefully. It is also saved in local storage. So now as soon as we click on toggle again. Let's see once whether it is saved in local storage or not. So yes, name here is saved in local storage. So now as we click on toggle, will the cleanup task perform now? Not at all. Now toggle again and see. The component is removed, unmounted, but we did not do any cleanup on unmounting. So now as we click on toggle again, data is coming from local storage. So this time you are not seeing any data cleanup here. What was happening last time? There was nothing there. In the state, we had given an empty string. When the component was re-rendering, that line was running and the whole state was getting empty. But this time we understand that the cleanup task is also important. If we are doing something like this, then we have to clean up when the component is unmounted. The form should have been completely empty, but it is not like that. If we are toggling, then the same name is coming here again. So, if you want to clean up, how will you do it? You have to perform the clean up task on unmounting. So, here you will put a useEffect. You know that we will give an empty dependency array like this. And for clean up, we don't do much. We just return the function. And when does this work? When the component is being unmounted. So, now what you can do here is, you will clear localStorage. So, your local storage will be cleared. Now if you see here, reload, we clicked on the toggle, right now it is minus because it is minus in local storage. Alright, and as soon as we click on the toggle again, it is unmounted. Your cleanup task should also be performed after unmounting, that means the entire local storage should be cleared. Now we are clicking on the toggle again, so you are not getting anything here because you had also cleaned the component while unmounting. The component was also cleaned while unmounting. This is what I want to explain to you. Now, it may not be the best example for you that you will understand the cleanup when you perform a task while unmounting. It may not be the best example. But when you come in real-world scenarios, when you are making projects, there are many scenarios where you are calling APIs, doing side effects tasks. So you are doing it through use effect. And at the same time, you are doing the cleanup task through use effect. If this component is unmounting, then we have to clean it in this way. In some components, it is not like that in every component, in some components, but yes, we do the cleanup task in this way, inside the use effect. This syntax. Okay, so you have to keep this in mind. And the rest of the API call, etc., you will know how to call API, side effect, etc. You know. You can also call API inside this use effect. So when your component will load, Data will come to you. I can make an example and show you here. And that example may be the best proof for you. So here, let's make data.jsx. Or users. We will call the API of users.jsx. R-A-F-C. And what will we do here? We will put a use effect. And whenever the component will load, we will ask for a data. From where will we ask? We will ask for data. From fake JSON placeholder. You know this site, you will find this site at the top of the json placeholder. So come down here, we will call fake data from this API. So you know how all this happens, it is very easy. We do not install exios for the time being, we run it with fetch. So our API is called. In return, we will get some response, const response is equal to, and here we can't use the weight of async, right? So for that, we have to use immediately invoke function expression, so that we can make async function from it. Do you know? Do you know this thing? I have told you in JavaScript and in previous React lectures. This is immediately invoke function expression. Here you can't work with async weight in useEffect. For sync await, you need a function, and you can't do this in this function. This function is in useEffect, you can't do this in this one. So for that, you have to make a function here, and then you have to call it here. It is better that you make a function like this, immediately invoke function, and call it like this. Okay? So we call this if, immediately invoke function expression. And you can write a function here. Like this. Look at this. This will be your function, okay? And by wrapping it in a bracket, we have called it here. All right, so now we can make this async. This is async and here is await. So whatever response will come, we will have to convert it to plain JavaScript, readable JavaScript object because the response will be coming in JSON. So by using response.json, we will convert it to readable format. And this will be our data. So let's do CLG. Do we see the data? Come here. We have not used the component yet. Let's come to app.jsx. And this same work with toggle. If toggle is true, then our component of users should be rendered here. Alright. So let's reload. So as soon as our users component is being rendered, API is being called here and the promise is visible. Why? Because we have not used await here. It also takes time in conversion. So we used await and now we can see the data. Now we will save this data in local storage. Although if the data is lost after reloading, then the API will be called again. But we don't want that. Suppose we want to save it in local storage. For now, let's show the data first. You have all the users, right? There is an array here. Let's just show the name of the array here. So first of all, you save this data. Cons data comma set data is equal to use state and this is your empty array. Empty array and here set data data. So data dot map. You will be getting items here one by one and you have to render that item here. Div item dot name. You are getting these basic basic things, right? So let's reload here, click on the toggle. So see this, you can see all the users you have here, all the users you have. And here we will put it in the key. Item dot ID will also be coming, maybe. Let's reload. toggle, ok, ID is also coming, so it is set properly here, very good, very good, so now when we click on toggle again, then see carefully what happens, see carefully, Understand my words carefully, what is happening here? For now, let's reload, there is no data, click on toggle, component will be loaded, component will be mounted, we have put a use effect on the mount, with that use effect, the data is being fetched, it will take a little time, it will look like a glitch, click on toggle, the data will come after clicking for a while, and as the data comes, it is being called again and again, why is this happening? Why is it getting called again and again? Because we haven't passed an empty dependency array. So the data is coming, changing in the state, the use effect is running again, changing in the state, the use effect is running again, and it got stuck in the loop. So this is very important to understand, that when it changes in the state, it will run the use effect, if you haven't passed the dependency array. So the data was getting set again and again, and the use effect was running. The data was getting set again and again, and the use effect was running. So that's why you can see it again and again. So now as soon as we toggle, I clicked, the data came after a while. And after calling, your data is set. Now as soon as I click on toggle again, we have not done the task of data cleanup, but when the component will be mounted again, then because MTRA has set it here, so this line will run, so MTRA will be set automatically. And then after that, data will come, sorry, data will load from here and then data will be set in data and data will be given. So it will look like you were saying this only. So as soon as you click on the toggle again, look carefully. I clicked. It took time to load the data. If I had saved the data in local storage again. Set local storage dot. Although there is no need to put it in local storage. But still, I am telling you to explain. I give the key data. And here json. Json. dot stringify we will put in local storage then only we will be able to put data stringify we put data here alright and here again local storage dot get item and stringify we will remove it we have given data here exactly so json dot stringify not stringify json dot parse we also do Data will be coming to the string from the local storage. So, we will pass it and return it to the normal format. For this, we have done this. And here we will also give an empty array in this way. If there is no data, null comes, then set an empty array here. So, what will you have in the starting? In the starting, there will be an empty array. Data has come to you. Data has been saved in the local storage. Now, as soon as we click on the toggle again, click on toggle again, component will be unmounted but data is still saved click on toggle again, data is still saved as soon as we click on toggle again, data is saved and data is fetched again and set again but old data was also available now, suppose you have to do clean up task now how to do clean up task now how to do clean up task for that again you have to use this syntax ok Set data and clear local storage. When you click on the toggle, the data will be cleaned up and the state will be cleared. When you click on the toggle again, the data will be loaded again. We mostly do this when we are using persist in redux, then data is saved. And if you want the fresh data to come when the component is mounted, then you do the cleanup at the time of unmounting, so that you get fresh data when it is mounted. So let's click on the toggle, see it took a little time to get the data, because the old data was cleaned up, the new data was fetched. In short, you have three phases, mount, updating and unmount. You have to implement logic according to these three phases. Often we have to run some logic in the updating phase. For that we have to keep in mind the updating phase. Often we want to perform some task on the load of the component. So for that you have mounting phase and all three are good use effects. After that unmount means when component is removed we have to perform some tasks, we have to perform some logic so that comes in our unmounting phase. So this was the component life cycle. This is what you have to understand that there are three phases. Birth, mounting, updating, update, changes and then unmounting. And according to that, you can do your logic etc. Rest in class based, you had these three. Component did mount, component did update, component will unmount. But now you can do all the work with use effects only because you have functional react now completely. So lifecycle is handled using hooks in functional react. Rest in class based component, it used to be different for everyone. It was very difficult. But now it is very easy for you. So important lifecycle hooks in functional react. If you see, useState is also very important to handle lifecycle method. Because you know that state only triggers re-render, causes lifecycle update. When the state changes, the use effect is running. So, this is the work of re-render trigger. You have understood the use effect. You have to do the task of side effect. If you want to handle the handle async work and life cycle phases, then you use use effect for that. So, we have understood the use state and use effect completely. So, if there is any problem related to this in our application, then we can solve it now. Can we do it? Exactly, now we can solve it. After that, we will discuss now, It will be in the sequence. Use memo, use callback. If you want to memorize the value, that means basically you have to store it. It is a repetitive task. Expensive calculations etc. So you have to store its result. Basically, you don't have to calculate again and again if it is the same task. So to memorize its value, you can use use memo. Use callback, you have to memorize the whole function. So we will see all this later. Okay. For that, use callback. And all these topics of yours, Actually, these are performance-oriented topics and you are asked a lot in interviews too. We have discussed use reference, how we can persist data without re-rendering, DOM references, previous value timers, we have seen all this in use reference and I have explained it properly. Then use layout effect, I am giving you the assignment, HW seems a bit childish to listen to. So I am giving you an assignment, you have to research about it. When will we use use layout effect? What is the difference between use effect and use layout effect? There is a small difference, but a very important difference. There is one such scenario where we can use use layout effect instead of use effect. So I am asking you when you can do this. So you comment and tell me. You will find it yourself. I have also told you that there is a scenario where we can use useLayout effect instead of useEffect. So what is that scenario or when can we use useLayout effect? Although in every case we can use useEffect for all the situations. where use layout effect can be better. What is that scenario? And when do you use use layout effect? And why use effect is better than use layout effect? So, all these things. So, we are going to discuss all these things. So, your whole cycle will be completed. Actually, your whole react will be completed. And then, after that, So, that's all for now. And thank you so much. See you in the next lecture. Till then, bye-bye.
