Skip to content

Dropping useQuery in favor of ensureQueryData + revalidateIfStale in loaders #9137

Answered by TkDodo
SebKranz asked this question in General
Discussion options

You must be logged in to vote

If it works for you, sure, why not. Just keep in mind that queries that don’t have an observer with useQuery or a similar hook are considered inactive (you can see that in the devtools), which means they are eligible for garbage collection, they won’t be refetched with invalidateQueries automatically etc.

That’s because React Query doesn’t know that you are “using” a query unless you explicitly subscribe to it with useQuery. Subscribing to the whole cache and doing your own thing bypasses this a bit.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SebKranz
Comment options

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