How to manually fetch while utilizing cache? #2141
Unanswered
joeattardi
asked this question in
Q&A
Replies: 1 comment
-
refetch is an imperative option that bypasses almost anything - I barely ever use it. react-query is declarative by nature. there a couple of steps you need to do to achieve this:
all in all, my impl would look something like this:
usage:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a component for a user to change their password.
As they type their password, it calls an API to check the password against configured password rules.
I don't want the query to fetch until a password is typed.
I thought I could do this by setting
enabled
tofalse
, then manually trigger it withrefetch()
. Unless I'm doing something wrong, it appears thatrefetch
doesn't check for a cached version of the data before sending the request.Say I type a password "z", then it makes the API call. Then I type another letter, it makes that API call. If I delete the second letter so that it's just "z", I would think it wouldn't make the fetch request again because the result for the query key ['checkPassword', 'z'] is already in the cache. Am I correct in the assumption that
refetch
bypasses the cache and always does a fetch?What would be the right way to do this? Is this a use case for a dependent query? Make it dependent on the password having a value, and then will it utilize the cache?
Beta Was this translation helpful? Give feedback.
All reactions