TanStackT
TanStack10mo ago
6 replies
specific-silver

If I set the queryFn to skipToken, can I omit the queryKey?

In the docs example:

 const { data } = useQuery({
    queryKey: ['todos', filter],
    // ⬇️ disabled as long as the filter is undefined or empty
    queryFn: filter ? () => fetchTodos(filter) : skipToken,
  })

when filter is undefined the queryKey becomes ['todos', undefined]. As far as I can tell this key will never result in a meaningful cache hit because data is never returned for this key. I would like to not have to generate a queryKey if I have empty arguments. Is this possible? I could set the queryKey to a dummy value like ['disabled'] but this could cause other problems if the same key is used elsewhere.
Was this page helpful?