useQuery executes a fetch function even though the query key is a falsy value.
I confirmed this behavior in latest version 2.5.14.
(My previos sample with version 1.2.1, useQuery doesn't fetch with falsy query key as described in the official docs.)
See my codesandbox.
https://codesandbox.io/s/falsy-querykey-mce4s?file=/src/App.tsx

Hey @oukayuka, I've been passing { enabled: false } whenever I want to do the conditional fetching, but curious to know the reason why we want to have the query key as null.
@chriszhangusc Yes, I know that and now I also use useQuery like this.
const { data: users = [] } = useQuery(
[orgCode, 'members'], (code) => getMembers(code), { enabled: !!orgCode },
);
But API Reference says,
https://react-query.tanstack.com/docs/api#usequery
Options
queryKey: String | [String, ...any] | falsy
I don't know when the specs changed, but if this is the correct behavior, shouldn't this | falsy be removed?
I assume many developers to think the query won't be executed when key is falsy, and actually previous versions and SWR do that.
@oukayuka Ohh you are right! Looks like a legit bug. Thanks for the clarification!
I'll update the docs :)
Most helpful comment
I'll update the docs :)