Describe the bug
I'm not able to memorize the result of useQueries. Every time the component renders, the useQueries creates a new result object which is not stable.
I tracked the issues here: #2991 but this didn't solved the issue
Even your example on https://tanstack.com/query/latest/docs/framework/react/reference/useQueries is not stable:
// Your example: --- FAIL
const ids = [1, 2, 3];
const results = useQueries({
queries: ids.map((id) => ({
queryKey: ["post", id],
queryFn: () => fetchPost(id),
staleTime: Infinity,
})),
});
// Try to memorize --- FAIL
const queries = useMemo(() => {
return [4, 5, 6].map((id) => ({
queryKey: ["post", id],
queryFn: () => fetchPost(id),
staleTime: Infinity,
}));
}, []);
const results2 = useQueries({
queries: queries,
});
// Another try to memorize --- FAIL
const queriesComplete = useMemo(() => {
return {
queries: [7, 8, 9].map((id) => ({
queryKey: ["post", id],
queryFn: () => fetchPost(id),
staleTime: Infinity,
})),
};
}, []);
const results3 = useQueries(queriesComplete);
Your minimal, reproducible example
https://codesandbox.io/p/devbox/vp3mys?file=%2Fsrc%2FApp.jsx%3A13%2C16
Updated*
Steps to reproduce
- Open the sandbox
- type text within the input
- See, that the counters going up, thats because the
useEffect deps are not stable
Expected behavior
I need a way to get a stable array results and the inner result too which coming from useQuery.
All my components rerender, even if they don't need to. My workaround was to put the entire useQueries in a lower memorized component and lift all states upwards which is really bad.
You may even want to add some documentation, if you found a way to solve this. The useQueries hooks is really annoying to use currently.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Windos
Tanstack Query adapter
react-query
TanStack Query version
5.18.1
TypeScript version
4.4.4
Additional context
No response
Describe the bug
I'm not able to memorize the result of
useQueries. Every time the component renders, the useQueries creates a new result object which is not stable.I tracked the issues here: #2991 but this didn't solved the issue
Even your example on https://tanstack.com/query/latest/docs/framework/react/reference/useQueries is not stable:
Your minimal, reproducible example
https://codesandbox.io/p/devbox/vp3mys?file=%2Fsrc%2FApp.jsx%3A13%2C16
Updated*
Steps to reproduce
useEffectdeps are not stableExpected behavior
I need a way to get a stable array results and the inner result too which coming from useQuery.
All my components rerender, even if they don't need to. My workaround was to put the entire useQueries in a lower memorized component and lift all states upwards which is really bad.
You may even want to add some documentation, if you found a way to solve this. The useQueries hooks is really annoying to use currently.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Windos
Tanstack Query adapter
react-query
TanStack Query version
5.18.1
TypeScript version
4.4.4
Additional context
No response