Enabled condition

I have "enabled" to only run if there is an objectType passed in, but for some reason it's still running even though objectType is undefined. I confirmed this by console.log objectType in the queryFn where it should always exist, but even in the log it show undefined. It's causing the network request to be like ...objectTypes/undefined/events...
I've never had this problem when using enabled so unsure what I'm doing wrong:

export const eventTypesForObjectQueryKey = (objectType: string) =>
  [
    { entity: Entities.AUDIT, scope: Scope.SELECTOR, subScope: SubScope.LIST, objectType, key: 'eventTypesForObject' },
  ] as const;

const fetchEventTypesForObject = async (objectType: string): Promise<IEventTypeForObject[]> => {
  console.log(objectType);

  const response = await http.get(ActivityLogService.getEventTypesForObjectURL(objectType));
  return unwrap(response);
};

export const useEventTypesForObject = (objectType?: string) => {
  return useQuery({
    queryKey: eventTypesForObjectQueryKey(objectType),
    queryFn: () => fetchEventTypesForObject(objectType),
    enabled: !!objectType,
  });
};

export interface IEventTypeForObject {
  type: string;
  translation: string;
}
Was this page helpful?