Skip to content

useBaseQuery onSubscribe is slow when mounting lots of useQuery instances #3756

Answered by dwilt
dwilt asked this question in Q&A
Discussion options

You must be logged in to vote

Update: After talking with @TkDodo (thanks for your help), we think the best approach here is to just reduce the number of usages of useQuery. There are a bunch of instances of them that we can move up to the top of our application and only have one instance since they don't update very often. In short, using useQuery has a bit of overhead (like useSWR) and if you have a lot of elements with a lot of instances per element, this can seriously add up because of the way observers are added and removed on mount and unmount.

To show an example of our change, we previously had a component on our screen with a useQuery like this:

Before:

// here's one of our reusable hooks that got used in a lot…

Replies: 4 comments 13 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@dwilt
Comment options

@dwilt
Comment options

Comment options

You must be logged in to vote
10 replies
@dwilt
Comment options

@TkDodo
Comment options

@TkDodo
Comment options

@dwilt
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by dwilt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants