Closed ryuina closed 1 year ago
Oh I found queryClient.invalidateQuery()
is still working even useQuery
key array has one more empty object. So the issue above is not a bug. 😢
So I close this issue, but can you consider this issue for consistency? I think it will be better if useQuery
key is equal to getKeyBy...
result
As the docs states this is on purpose, to invalide a wider range of keys. But i see the point. An option to customise behaviour will be a solution. This is already tracked on another issue
Hi, I'm using zodios-react hooks with a lot of joy, it is really helpful and type-safe. I don't need to waist more time to make hooks :) But I found an unexpected result about the generated key.
The problem happens when I call a query without any configs like
hooks.useGetUsers()
. But the query key is not equal tohooks.getKeyByAlias('getUsers')
, so I couldn't invalidate that query if I want to call and update in different pages (because I cannot use invalidate() method from the useQuery result).What I wanted from source code:
hooks.spec.tsx
hooks.ts
It's because the
pick()
function always returns an object even a config is undefined, thereforequeryResult.key
is set like this[{api: '...', path: '...'}, {}]
.If
pick()
returns an object every time, the result of the useQuery key also should be always length two.But the functions
getKeyByPath
andgetKeyByAlias
still return length 1 array when the config is undefined.In this case, useQuery without any params or configs, we cannot invalidate that query because the key, generated, announced to queryClient is not equal to
getKeyBy...()
result.(Anyway, if I were you, I'll fix
pick()
to returnundefined
when config is empty to make the QueryKey more clean)