T
TanStack17mo ago
exotic-emerald

Query invalidation

hi, how do you recommend query invalidation for this type of query?
export function getAdminStatistics() {
return useQuery<AdminStatistics>({
queryKey: ["statistics"],
async queryFn() {
const result = {
activeProperties: 0,
agencies: 0,
landlords: 0,
developmentCompanies: 0,
};

[
result.activeProperties,
result.agencies,
result.landlords,
result.developmentCompanies,
] = await Promise.all([
queryDocumentsCount(
newQuery("properties")
.where("accepted", "==", true)
.where("visible", "==", true),
),
queryDocumentsCount(newQuery("agencies")),
queryDocumentsCount(
newQuery("users").where("data.credentials", "==", "landlord"),
),
queryDocumentsCount(newQuery("development-companies")),
]);

return result;
},
initialData: {
activeProperties: 0,
agencies: 0,
landlords: 0,
developmentCompanies: 0,
},
});
}
export function getAdminStatistics() {
return useQuery<AdminStatistics>({
queryKey: ["statistics"],
async queryFn() {
const result = {
activeProperties: 0,
agencies: 0,
landlords: 0,
developmentCompanies: 0,
};

[
result.activeProperties,
result.agencies,
result.landlords,
result.developmentCompanies,
] = await Promise.all([
queryDocumentsCount(
newQuery("properties")
.where("accepted", "==", true)
.where("visible", "==", true),
),
queryDocumentsCount(newQuery("agencies")),
queryDocumentsCount(
newQuery("users").where("data.credentials", "==", "landlord"),
),
queryDocumentsCount(newQuery("development-companies")),
]);

return result;
},
initialData: {
activeProperties: 0,
agencies: 0,
landlords: 0,
developmentCompanies: 0,
},
});
}
how can i inform the statistics query that a new agency has been added ?
1 Reply
robust-apricot
robust-apricot17mo ago
usually, when you fire a mutation that adds a new agency, you invalidate the corresponding queries

Did you find this page helpful?