T
TanStack•3y ago
stormy-gold

Set query data for query with nested array query key

I have a query with queryKey: ['foo', ['bar']] which I want to update the query data for. When I do queryClient.setQueriesData(['foo'], ...) it works fine (although I get queries I dont want aswell), but when I do: queryClient.setQueriesData(['foo', ['bar']], ...) Then it doesnt update for my query, it does not seem able to match the query keys. I have confirmed that the query key is ['foo', ['bar']] by printing the queryClient in the browser console and looking at the queries. Could it be a problem that the element in the querykey param is an array and not a primitive? 🤔 I am probably doing something trivial thing wrong 😄 Any help is appreciated!
3 Replies
like-gold
like-gold•3y ago
can you show this in a quick codesandbox please? should be easy to reproduce
stormy-gold
stormy-goldOP•3y ago
I solved it! I was missing a param in between foo and [bar] , I didnt know that the order mattered. When I added it inbetween it worked. Thank you for reaching out!
like-gold
like-gold•3y ago
arrays have an order 🙂 If you want no-order, use objects

Did you find this page helpful?