-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Description
Describe the bug
When using useQueries, the owning component rerenders repeatedly.
To Reproduce
Steps to reproduce the behavior:
- call useQueries()
- put a console log in the render method, or add a useeffect:
const result = useQueries(...);
useEffect(() => {
console.log('result changed!');
}, [result]);
Expected behavior
The component should not be rerendered constantly
Desktop (please complete the following information):
- OS: MacOS
- Browser: Chrome
- Version: 96
Additional context
This is due to a missing useMemo()
: https://github.com/tannerlinsley/react-query/blob/master/src/react/useQueries.ts#L121
The problem is that later in that function, a useEffect fires, which updates state, which causes everything to rerender, which causes this array to be generated again.
A simple useMemo()
fixes the problem. Working on a PR now
narthur, colincheng5 and chpio