tRPCttRPC
Powered by
FleetAdmiralJakob 🗕 🗗 🗙F
tRPC•2y ago•
4 replies
FleetAdmiralJakob 🗕 🗗 🗙

Return undefined if param is not there

In this code cityById could be undefined and I want that this checks this and then weatherData gets undefined.

Problem: I can't wrap this in a condition because of React's Hook Rules

  const weatherData = api.weather.getWeather.useQuery(
    {
      coordinates: cityById.coord,
      timezone: dayjs.tz.guess(),
      lang: locale,
    },
    { refetchOnWindowFocus: false, staleTime: 1000 * 60 * 60 /* 1 hour */ },
  );
  const weatherData = api.weather.getWeather.useQuery(
    {
      coordinates: cityById.coord,
      timezone: dayjs.tz.guess(),
      lang: locale,
    },
    { refetchOnWindowFocus: false, staleTime: 1000 * 60 * 60 /* 1 hour */ },
  );
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

TypeError: queryClient.getMutationDefaults is not a function (it is undefined)
tmy03Ttmy03 / ❓-help
3y ago
Frozen input param
MugetsuMMugetsu / ❓-help
4y ago