Skip to content

Can't pass a string value as the first parameter of useQuery() #2149

@mw999

Description

@mw999

Describe the bug
When passing a string as the first parameter of useQuery(), it doesn't get passed into the defaultQueryFn correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Create a defaultQueryFn for your QueryClient
  2. Provider the QueryClient using QueryClientProvider.
  3. Try and run a query with useQuery('my-endpoint')
  4. See incorrect params being passed to defaultQueryFn

Expected behavior
The queryKey passed to the defaultQueryFn should be in the format [key, params], no matter if useQuery() has been passed an array, string or object as the first parameter.

const defaultQueryFn = async ({ queryKey }) => {
  const [key, params = {}] = queryKey;

  // should equal { key: 'my-endpoint', params: {} }
  // actually equals { key: 'm', params: y} }
  console.log({ key, params })
});

//

const query = useQuery('my-endpoint');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions