Skip to content

useQuery triggers extra renders in React #77

@Kostanos

Description

@Kostanos

Hey, first of all thank you for the library.

I have a question, maybe I misses something:
Why useQuery provokes 2 extra renders in react? Instead it should only provoke:

  • one render if I don't read loading/loaded variable, only when the data is ready
  • two renders if I read them - one fore loading = true, loaded = false and the second one for loading = false, loaded = true

But for some reason, I see 3 or some times 4 renders:

const { data, loading, loaded } = useQuery(myQuery, variables);

 render   |  loading  |  loaded   | data
-------------------------------------------
   1      |  false    |   false   | null     - expected
   2      |  true     |    false  | null     - expected
   3      |  true     |    false  | null     - why ????
   4      |  true     |    false  | null     - why ????
   5      |  false    |    true   | { data } - expected

PS. I'm trying to optimize the code and to reduce the amount of unnecessary renders, and I found this unexpected behavior. (Apollo client doesn't have it)

BTW. useSuspenseQuery works as expected, but it has different issue I posted in the separate topic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions