Skip to content

Prefetch hook keys aren't properly set #102

Closed
@nopitown

Description

@nopitown

Describe the bug
I started using the prefetch hooks introduced a few days ago, but the dynamic key is hardcoded, making it challenging to use the prefetched data because the keys do not match.

To Reproduce
Just generate the hooks and check the prefetch code.

Here is an example of the code generated:

export const prefetchUseFooServiceGetBar = (queryClient: QueryClient) =>
  queryClient.prefetchQuery({
    queryKey: [Common.useUseFooServiceGetBarKey, []],
    queryFn: () => FooService.getBar(),
  });

OpenAPI spec file
N/A

Expected behavior
Similar to a query hook, the keys must be dynamic so we can tell React Query what key should be used for caching:

export const prefetchUseFooServiceGetBar = (queryClient: QueryClient, queryKey?: TQueryKey) =>
  queryClient.prefetchQuery({
    queryKey: Common.useUseFooServiceGetBarKeyFn(queryKey),
    queryFn: () => FooService.getBar(),
  });

Screenshots

  • OS: MacOS
  • Version: 14.4.1

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions