Open
Description
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
- Use the
useList
hook - Add
queryOptions.select: (data) => { console.log('select'); return data }
- 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