From the course: TanStack Query: Efficient Data Fetching and State Management
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Optimizing with useQueries - TanStack Query Tutorial
From the course: TanStack Query: Efficient Data Fetching and State Management
Optimizing with useQueries
- [Instructor] So far, we are making a request to the GitHub API for both of these different users. We have different used query hooks, and we have these hardcoded little react elements here that are pretty redundant. So I'm sure that there's some sort of a way that we can make this a little better. And all of that starts with changing this use query hook to use queries. So use queries, the plural says it all, will allow us to send multiple parallel dynamic queries. And this is particularly useful when the values change from render to render. So let's say one time we're rendering six different users. One time we render two use queries is going to help us do that efficiently. So let's take a look right underneath our query client, we're going to create a function called fetch GitHub user. We're going to set that equal to an asynchronous function. That's going to take in a username as a parameter. Then we'll say cons response equals a weight fetch. Let's then say…