TanStackT
TanStack6mo ago
3 replies
ordinary-sapphire

invalidating the first key doesn't work

in tanstack query, what are the possible reason why invalidating ["user"] doesn't invalidate ["user", "some-username", "posts"]? i'm sure that i'm using correct
queryClient
as well
// useQuery
const threadsQuery = useInfiniteQuery(userThreadsInfiniteOptions(username));

// options
export const userOptions = queryOptions({
  queryKey: ["user"],
});

export const userThreadsInfiniteOptions = (username: string) => {
  return infiniteQueryOptions({
    queryKey: [userOptions.queryKey, username, threadInfiniteOptions.queryKey],
    initialPageParam: undefined,
    queryFn: async ({ pageParam }: { pageParam: string | undefined }) =>
      getUserThreads({
        username,
        lastId: pageParam,
      }),
    getNextPageParam: (posts) => {
      if (posts.length === 0) return undefined;

      return posts[posts.length - 1].id;
    },
  });
};

// invalidation
  queryClient.invalidateQueries({
    queryKey: userOptions.queryKey,
  });
Was this page helpful?