Calling refetch but with different url parameters?
Hello,
I want to call 'refetch' on a useQuery, but with a variation of url parameters.
Use case: I have a set of buttons, which I want to make a GET call with slight variations, using the same useQuery for convenience.
How can I pass these parameters to the query function?
4 Replies
fascinating-indigo•3y ago
I think you might need to look at this with a slightly different mental modal. As far as I understand,
refetch refetches the query; it doesn't change anything about the query itself (like the URL in your example).
I think the idiomatic way to do what you're describing (to fetch from a different URL) is to use a query key comprised of those parameters so that it can be identified as a different query (because it is) and fetched if necessary. You can use the same custom hook as an abstraction over useQuery and pass it any arguments that need to form part of the query key.quickest-silverOP•3y ago
Thank you!
fascinating-indigo•3y ago
No worries. Let me know if this works for you or if you need a hand 👍
rising-crimson•3y ago
React Query FAQs
Answering the most frequently asked React Query questions