From the course: Building a GraphQL Project with React.js

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Using the Callback hook

Using the Callback hook

- [Instructor] Now you may have noticed when you were looking at the console in our application that our application was retrieving the data more than once. So let's go ahead and refresh this and you can see that. So by reloading, we get the data from the server twice. That's because the user fact feature will rerun there this data, as we fetch it from the server and it might do that more than once. As our application grows, this is going to become more of a problem. So we can use a different hook called useCallback to optimize how, and when items are rendered in our application. This is called memorization and essentially it's going to remember our data and not update it unless we need it to. So let's go ahead and use this in our application. So I'm going to save this and what I'm going to do is take most of this fetch out of the use effect section here, and I'm going to create a new variable here or a new method. So…

Contents