T
TanStack2y ago
stormy-gold

query cache performance

is there any significant difference between using const {data} = useSomething(params) or inifite query and useSomething(params) const query = queryCache.find(params) and useSomething(params) const data = queryClient.getQueryData(params) or the second and third example is just bad practice ?
7 Replies
genetic-orange
genetic-orange2y ago
useQuery is the main API. Use it. You have to have a good reason to use the other ways of accessing the cache. Technically, the difference is significant but from a user point of view it is not. useQuery creates a subscriber to the cache, the other approaches do not.
stormy-gold
stormy-goldOP2y ago
what you mean by "significant but nor from user view" ? i see the difference in the API but i see no problem using queryCache.find. the question: is there any ram or cpu difference can i measure it?
genetic-orange
genetic-orange2y ago
Of course you could measure it. But I highly doubt that your application would profit from optimizations like that.
stormy-gold
stormy-goldOP2y ago
what if i need to use pagination? usequery and useinfinitequery are the same ?
genetic-orange
genetic-orange2y ago
Explain your use case and we might be able to help you
stormy-gold
stormy-goldOP2y ago
i want to fetch many pages render after render and get the sum of data. some time data may not come or smt went wrong with the query. i want be able to still to fetch ie 1.2.3.4.5[broken page].6.7.8.9 still want to get 1.2.3.4.7.8.9 pages data
rare-sapphire
rare-sapphire2y ago
The difference is significant because only useQuery creates a subscription to the cache. Your components won't rerender correctly without it

Did you find this page helpful?