-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Make QueryKey consistently an Array #2919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this change is great but we have a type "symmetry" DX issue:
A solution could be to add an alias: So
It also means no breaking changes. |
We already do it for the other callbacks that can retrieve an arbitrary query don't get it that way, which is why this issue was suggested. Maybe the best thing would be to take away the |
Right!
The v4 could be a great opportunity for this change! |
@tannerlinsley would you also agree to that? |
Sorry, I'm not sure what I'm agreeing to exactly |
@tannerlinsley the initial proposal was to have the The new proposal would take this one step further and always need an array for the The reasoning is that it might come across as confusing if you call |
Tanner just said we can always use Arrays 🚀 |
we could also add a codemod to this :) |
@balazsmatepetro FYI |
* fix: ensure mutationKey is an array react query will require all keys be an array. see: TanStack/query#2919 * chore: yarn changeset * chore: yarn generate:examples * chore: yarn changeset * test(plugins/react-query): fix tests + update snapshots Co-authored-by: Charly POLY <[email protected]>
When we pass the
queryKey
to theQueryFunctionContext
, we make sure that it is an Array. This is great for global query functions, because you can just work with anArray<unknown>
on type level.However, in other situations where we provide the whole
Query
, accessingquery.queryKey
will still bestring|Array<unknown>
. For example, when using thepredicate
filter:here, it is not guaranteed that
query.queryKey
is an Array, so it's harder to work withProposed solution
only allow
Arrays
forQueryKeys
(and forMutationKeys
as well)a codemod would be very good for this. we could let it run over all our examples, and we'd also need to update everything in the docs.
things to take care about:
The text was updated successfully, but these errors were encountered: