Skip to content

useQueries causes constant rerenders #2991

@alecf

Description

@alecf

Describe the bug
When using useQueries, the owning component rerenders repeatedly.

To Reproduce
Steps to reproduce the behavior:

  1. call useQueries()
  2. 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

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