Some way to check if the query in Next.js is loading or some way to check if the query was skipped?

I currently have a problem where I want to check if my query was skipped or if it is just waiting for the response.

  const { locale, query, replace } = useRouter();

  const cityById = useQuery(
    convexApi.getCity.findCityById,
    typeof query.cityId === "string" ? { id: parseInt(query.cityId) } : "skip",
  );

  if (!(typeof query.cityId === "string")) { /* <- This somehow always is triggered/true so idk maybe a stupid idea to check for that */
    if (activeCity$.id.get() !== 0 && activeCity$.name.get() !== "") {
      void replace("/home?cityId=" + activeCity$.id.get());
      return;
    } else {
      void replace("/search");
      return;
    }
  }
Was this page helpful?