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 example and understanding

useCallback example and understanding

Hello and welcome back. Let's go through our use callback example. Let's revisit our example first and what are the details of this example and then we move on to the code to see this in effect. So far what we know is that without use callback and in this particular example we are going to use a parent and child component. The parent component is going to have a state defined as count and it is also going to have an increment function. The increment function will be created using the use callback hook so that this particular function can be memoized. this function, we are simply receiving the set count function and on the basis of the previous count, we are updating it by one. Lastly, we have the child component that is getting re-rendered and the return of that child component is actually going to have an on click event and that increment function which is created using the use callback is actually going to be passed here by reference. Below we have the child component which is being…

Contents