-
-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
It would be nice if the arguments for the generated hooks had a default value if all the properties of the argument can be undefined.
Example of generated hook as is:
export const useCatsServiceGetCats = <
TData = CatServiceGetCatsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[]
>(
{
color,
age,
}: {
color?: string;
age?: number;
},
queryKey?: TQueryKey,
options?: Omit<
UseQueryOptions<TData, TError>,
"queryKey" | "queryFn" | "initialData"
>
) =>
useQuery<TData, TError>({
queryKey: [
useCatsServiceGetCatssKey,
...(queryKey ?? [{ color, age }]),
],
queryFn: () =>
CatsService.getCats(color, age) as TData,
...options,
});
// usage - need to pass empty object at least
const {data} = useCatsServiceGetCats({});
Example of proposed generated code:
export const useCatsServiceGetCats = <
TData = CatServiceGetCatsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[]
>(
{
color,
age,
}: {
color?: string;
age?: number;
} = {}, // this is defaulted since all properties can be undefined
queryKey?: TQueryKey,
options?: Omit<
UseQueryOptions<TData, TError>,
"queryKey" | "queryFn" | "initialData"
>
) =>
useQuery<TData, TError>({
queryKey: [
useCatsServiceGetCatssKey,
...(queryKey ?? [{ color, age }]),
],
queryFn: () =>
CatsService.getCats(color, age) as TData,
...options,
});
// usage - no need to pass empty object
const {data} = useCatsServiceGetCats();
7nohe
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers