T
TanStack3y ago
fair-rose

How to pass new params into an existing invalidation

Hi all, I just made a post but actually narrowed down the issue, I'm keeping that post open as it has some context that might be useful. Please check it out if you'd like a bit of background on what I'm doing. Essentially I have an analytics page and whenever someone changes the date range or updates their current view we refetch some data. I have it setup right now to where if you make those changes, data refetches but the query doesn't actually use new params. Same id, same "date range" same view, same everything. I confirmed this through the network tab on my devtools. I need to somehow REFETCH/invalidate AND update the params to the new ones. Thanks!
3 Replies
automatic-azure
automatic-azure3y ago
You can’t refetch with new parameters. That wouldn’t be a refetch, that would be a different query. Assuming your query key is comprised of the necessary parameters (which it should be; please see the documentation on query keys if it’s not and/or you don’t understand their purpose), it’ll automatically fetch the new data using the new parameters, assuming there’s not an entry in the cache for the given query key. If there is, it’ll use that cache entry. You can opt out of caching or invalidate queries imperatively if required. See: https://tkdodo.eu/blog/react-query-fa-qs#how-can-i-pass-parameters-to-refetch
fair-rose
fair-roseOP3y ago
Every time I doubt myself about react query the react query deity himself tk dodo has written a blog about it Thank you, this will solve my issue! The Dan Abramov of this library
automatic-azure
automatic-azure3y ago
No worries, Dominik's blog is fantastic :reactquery:

Did you find this page helpful?