🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
You can even invalidate queries with specific variables by passing a more specific query key to the `invalidateQueries` method:
[//]: # 'Example3'
```ts
queryClient.invalidateQueries({
queryKey:['todos',{type:'done'}],
})
// The query below will be invalidated
todoListQuery=injectQuery(()=>({
queryKey:['todos',{type:'done'}],
queryFn: fetchTodoList,
}))
// However, the following query below will NOT be invalidated
todoListQuery=injectQuery(()=>({
queryKey:['todos'],
queryFn: fetchTodoList,
}))
```
[//]: # 'Example3'
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:
[//]: # 'Example4'
```ts
queryClient.invalidateQueries({
queryKey:['todos'],
exact: true,
})
// The query below will be invalidated
todoListQuery=injectQuery(()=>({
queryKey:['todos'],
queryFn: fetchTodoList,
}))
// However, the following query below will NOT be invalidated
consttodoListQuery=injectQuery(()=>({
queryKey:['todos',{type:'done'}],
queryFn: fetchTodoList,
}))
```
[//]: # 'Example4'
If you find yourself wanting **even more** granularity, you can pass a predicate function to the `invalidateQueries` method. This function will receive each `Query` instance from the query cache and allow you to return `true` or `false` for whether you want to invalidate that query: