TanStackT
TanStack2y ago
1 reply
dangerous-fuchsia

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,
    },
  });
}




how can i inform the statistics query that a new agency has been added ?
Was this page helpful?