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 */ },
  );
Was this page helpful?