stale option doesn't work in refetch method #4432
-
DescrptionI 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. The problem is that I want the refetch method to respect the staleTime, I'm trying to pass the stale option as true, but the request is fired anyway. I would like to know if this is the expected behavior and how I could solve this problem. Evidence:Screen.Recording.2022-11-02.at.16.50.03.mov |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Yes, this is the expected behaviour.
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 |
Beta Was this translation helpful? Give feedback.
-
Ok, but the refetch function takes these parameters. I still don't understand why they exist, do they really work? |
Beta Was this translation helpful? Give feedback.
Yes, this is the expected behaviour.
refetch
returned fromuseQuery
is an unconditional fetch - the only thing that can bypass theenabled
option. By doing this, you opt-out of most of the cool features that react-query offers, like respectingstaleTime
.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.