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.

Nesting query keys hierarchically

Nesting query keys hierarchically

- [Instructor] Let's take a look at how we can make some adjustments to the queryKey, so that we can manage our query keys more effectively. So, as our applications balloon in size, we'll have more and more queries on the page. And it feels like it's okay, probably, to have a user query, but you may want to consider structuring them differently to make them more maintainable. Let me show you what I mean by that. So what we'll do here on line 33, is we'll add github to the top of this queryKey, then we're going to incorporate from ReactQuery another function called useQueryClient. Now, useQueryClient, it starts with the word use, so we know it's a hook, it is going to tell our GitHubProfiles component some information about these users. So let me show you what I mean. We're going to create a value called queryClient, set that to useQueryClient, so this'll give us access to the QueryClient. From here, we're going to create a couple different functions. So underneath our use queries…

Contents