Skip to content

useQuery causes multiple renders #1490

Answered by kitten
novaknole asked this question in Q&A
Discussion options

You must be logged in to vote

It's not quite a re-render and this is expected behaviour and required, especially to comply with the rules of concurrent mode for concurrent mode safety, suspense, and the rules of hooks in general. What's actually happening is that the initial mount has consistent state with the subsequent renders, but the effect will have to actually start the side-effects of executing queries, so they will at least call setState once to update the result, even if it's identical to the last, since it may have changed from the time of render.

The useQuery code in urql is pretty optimised, but has also been rewritten to comply to as many guidances and rules of the React team as possible to ensure that it…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@novaknole
Comment options

@kitten
Comment options

Answer selected by kitten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants