I'm using React Query and I want to update cache after the mutation, but I want to update multiple keys in one go.
I have "invoices" and ["invoice", 1] and I update it as follows:
queryClient.setQueryData("invoices", ({invoices}) => {
return {
invoices: [
...filter(invoices, invoice => invoice.id !== activeInvoice),
{
...find(invoices, invoice => invoice.id === activeInvoice),
customer: data?.updateInvoiceCustomer?.customer
}
]
}
})
queryClient.setQueryData(["invoice", activeInvoice], ({invoice}) => {
return {
invoice: {
...invoice,
customer: data?.updateInvoiceCustomer?.customer
}
}
})
Thus, now I do it per key. Is there any way to do it in one go and to use something like this:
queryClient.setQueriesData(["invoices", ["invoice", activeInvoice]], ({invoices, invoice}) => {
return {
invoices: [
...filter(invoices, invoice => invoice.id !== activeInvoice),
{
...find(invoices, invoice => invoice.id === activeInvoice),
customer: data?.updateInvoiceCustomer?.customer
}
],
invoice: {
invoice: {
...invoice,
customer: data?.updateInvoiceCustomer?.customer
}
}
}
})
Thanks