Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryKeys: default query keys to include any params #9

Merged
merged 1 commit into from
Mar 27, 2023

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