lukemorales/query-key-factory

why does `enabled` not work within the query-key-factory?

ethanneff opened this issue · 1 comments

Why does this fail?

const query = useQuery(queries.shipmentFees.available(params, enabled));

export const queries = createQueryKeyStore({
  shipmentFees: {
    available: (params: ShipmentFeesEndpointFetchAvailableRequest, enabled: boolean) => ({
      enabled,
      queryKey: [apiEndpointHandler, params],
      queryFn: () => ShipmentFeesEndpoint(apiEndpointHandler).fetchAvailable(params, { splitArrayParams: true }),
    }),
  },
});

And this work?

const query = useQuery({ ...queries.shipmentFees.available(params), enabled });

export const queries = createQueryKeyStore({
  shipmentFees: {
    available: (params: ShipmentFeesEndpointFetchAvailableRequest) => ({
      queryKey: [apiEndpointHandler, params],
      queryFn: () => ShipmentFeesEndpoint(apiEndpointHandler).fetchAvailable(params, { splitArrayParams: true }),
    }),
  },
});

The simple answer is: it doesn't work because it was never supposed to work (sorry if this sounds rude, but that's just it). The documentation and the type system is pretty clear about what properties the objects accept.