Skip to content

stale option doesn't work in refetch method #4432

Answered by TkDodo
fhugoduarte asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, this is the expected behaviour. refetch returned from useQuery is an unconditional fetch - the only thing that can bypass the enabled option. By doing this, you opt-out of most of the cool features that react-query offers, like respecting staleTime.

I would like to call my query imperatively. For that I passed the enable option as false and I'm using the refetch to execute the query.

I would argue that this is still not the right way to go about it in most cases. You can have queries be lazily evaluated with a dynamic enabled option. Have a look at lazy queries.

Replies: 2 comments 4 replies

Comment options

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

Answer selected by fhugoduarte
Comment options

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

@fhugoduarte
Comment options

@TkDodo
Comment options

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