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.

useCallback introduction

useCallback introduction

Hello and welcome back. In the lesson number 8, we are going to start off the learning for use callback hook. So let's begin what a use callback hook is used for. So use callback hook is pretty similar to the previous use memo hook we discussed but But there are slight changes based on the requirements that we have. UseCallbackHook returns a memoized version of a callback function. It prevents the recreation of the function unless the dependencies of that function actually changes. That's how a basic syntax of use callback hook looks like. Now let's understand what we have stated above in detail. As we know that whenever we are providing a props or a state value that gets changes, we get a re-render on the component. And whenever we have a re-render in effect, that means all the functions that we have defined, whether they are handle clicks or the other functions that we have written, they get to recreate it. Because whenever a re-render occurs, your functions are also recreated on…

Contents