T
TanStack•3y ago
other-emerald

invalidate multiple queries

How would I invalidate the following sets of queries in a single invalidateQueries call?:
onSuccess: (_, variables) => {
queryClient.invalidateQueries([
QueryKeys.Item,
variables.itemId.toString(),
]);
queryClient.invalidateQueries([QueryKeys.InventoryItems]);
queryClient.invalidateQueries([
QueryKeys.CheckInItem,
variables.itemId.toString(),
]);
},
onSuccess: (_, variables) => {
queryClient.invalidateQueries([
QueryKeys.Item,
variables.itemId.toString(),
]);
queryClient.invalidateQueries([QueryKeys.InventoryItems]);
queryClient.invalidateQueries([
QueryKeys.CheckInItem,
variables.itemId.toString(),
]);
},
2 Replies
foreign-sapphire
foreign-sapphire•3y ago
Give them all the same key prefix, something like item
other-emerald
other-emeraldOP•3y ago
ah and if i want to control thjem individiually, i.e. ["item", id, "checkin"], and ["item", id] - and in this case i can invalidate these 2 only (if i wish) with ["item", id] yeah, smart 🙂 thanks

Did you find this page helpful?