Skip to content

[BUG] queryOptions.select runs multiple times #6713

Open
@jpenna

Description

@jpenna

Describe the bug

I'm using GraphQL and I'm changing the data with the React Query's select middleware. It should run only once per request, but it is running multiple times.

Steps To Reproduce

  1. Use the useList hook
  2. Add queryOptions.select: (data) => { console.log('select'); return data }
  3. See "select" is logged multiple times

Replication CodeSandbox: https://codesandbox.io/p/sandbox/react-query-5-forked-hh85pv

Expected behavior

It should run only once. In React Query's documentation, they say to memoize the select function: https://tanstack.com/query/latest/docs/framework/react/guides/render-optimizations#memoization

useList is changing the function reference on every render.

Packages

  • "@refinedev/core": "^4.54.0",

Additional Context

Possible fix: pass the select function inside a useCallback to useList's useQuery

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions