Skip to content

Conversation

@seriouslag
Copy link
Collaborator

@seriouslag seriouslag commented Mar 26, 2023

This PR is to default the query keys to include any query params and to allow more than only string[] for query keys.

See: https://tanstack.com/query/v4/docs/react/guides/query-keys#array-keys-with-variables

export const useCatServiceGetCatById = <TQueryKey extends Array<unknown> = unknown[]>({ catId }: {
    catId: string;
}, queryKey: TQueryKey, options?: Omit<UseQueryOptions<Awaited<ReturnType<typeof CatServive.getCatById>>, unknown, Awaited<ReturnType<typeof CatService.getCatById>>, string[]>, "queryKey" | "queryFn" | "initialData">) => {
  return useQuery([useCatServiceGetCatByIdKey, ...(queryKeys ?? [{
    catId,
  }])], () => CatService.getCatById(catId), options);
}

@seriouslag seriouslag force-pushed the patch/default-query-keys-to-params branch from 0c4a550 to 2223a58 Compare March 26, 2023 21:42
@7nohe
Copy link
Owner

7nohe commented Mar 27, 2023

@seriouslag Thank you for contributing! This looks good, so I will merge this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants