TanStackT
TanStack•2y ago•
6 replies
popular-magenta

getQueryData returning undefined

Using the query keys factory with the query options API that @TkDodo šŸ”® wrote about in his blog, I'm trying to update the product list cache when editing a product.

Query Keys:
export const productQueries = {
  all: () => ['products'],
  lists: () => [...productQueries.all(), 'list'],
  list: (filters: ProductFilters = {}) =>
    queryOptions({
      queryKey: [...productQueries.lists(), filters],
      queryFn: () => fetchProductsList(filters),
    }),
}


The final query key looks like this:
['products', 'list', {page: 1, per_page: 20}]

When I try to do queryClient.getQueryData(productQueries.list().queryKey), it's returning undefined.

When I try with lists(), it also returns undefined.

Does getQueryData not return all matching queries? Only exact ones?
Using invalidateQueries works without having to pass the filters inside the query key.
Was this page helpful?