T
TanStack3y ago
conscious-sapphire

Default query key/function on a key store?

So, I am running into an odd case of having to define a key for something in a way is already defined, and I have repeating names:
import { useQuery } from "@tanstack/react-query";
import { queryKeyStore } from "state";

export const useCustomer = () => {
const getCustomerQuery = useQuery({
...queryKeyStore.customer.customer()
});

return getCustomerQuery;
};
import { useQuery } from "@tanstack/react-query";
import { queryKeyStore } from "state";

export const useCustomer = () => {
const getCustomerQuery = useQuery({
...queryKeyStore.customer.customer()
});

return getCustomerQuery;
};
and this is my store:
import { createQueryKeys } from "@lukemorales/query-key-factory";
import { CustomerService } from "services/shopify/CustomerService";

export const customerKeyStore = createQueryKeys("customer", {
customer: () => ({
queryKey: ["customer"],
queryFn: async () => {
const productsService = new CustomerService();

return await productsService.getCustomer();
}
})
});
import { createQueryKeys } from "@lukemorales/query-key-factory";
import { CustomerService } from "services/shopify/CustomerService";

export const customerKeyStore = createQueryKeys("customer", {
customer: () => ({
queryKey: ["customer"],
queryFn: async () => {
const productsService = new CustomerService();

return await productsService.getCustomer();
}
})
});
So is there a way to avoid the double customer.customer()? and have the base one as simply queryKeyStore.customer() like a default one? Or do I have to always think of a name for the "base query" in the store?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?