T
TanStack•3y ago
old-apricot

objects matching behaviour

Say I have the following query keys:
{
singleTodoById: (id?: string) => ['todos', { id }];
}
{
singleTodoById: (id?: string) => ['todos', { id }];
}
and say I do this
queryClient.refetchQueries(keys.singleTodoById());
queryClient.refetchQueries(keys.singleTodoById());
note I didn't pass an Id, so the generated key would be ['todos', {}]. Would that match all my subsequent keys, with ids defined, or not? 🤔
4 Replies
old-apricot
old-apricotOP•3y ago
where is it stated in the docs that this is how it works?
other-emerald
other-emerald•3y ago
The invalidateQueries API is very flexible, so even if you want to only invalidate todos queries that don't have any more variables or subkeys, you can pass an exact: true option to the invalidateQueries method:
old-apricot
old-apricotOP•3y ago
I see so it would only try to match variables I provided, and if I didn't it'll pass thanks

Did you find this page helpful?