-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add a skipToken
that resets the query hook if it's been initialized before (e.g. skipOrResetToken
)
#2411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Seems plausible. I also don't think we have a way to reset a single cache entry imperatively atm - you can reset the entire API state, but not just one entry. |
I think the point here is more to reset the hook rather than the cache entry, right? |
Yes, it's about resetting the hook -- I'll edit the title. Here's a more detailed example of the type of code I currently end up writing: const { connectedAccount } = useAccountContext();
const accountSettingsQuery = useAccountSettingsQuery(connectedAccount ? { account: connectedAccount } : skipToken);
const accountSettings = connectedAccount ? accountSettingQuery?.data : undefined;
// and then render something based on the settings
There's an argument to be made that I should just re-mount the component for such a context change (fair). Or that the extra variable solution is simple (which it is) but the main issue with it is that it's easy to miss. I mistakenly tend to take for granted that when |
skipToken
that resets the query if it's been initialized before (e.g. skipOrResetToken
)skipToken
that resets the query hook if it's been initialized before (e.g. skipOrResetToken
)
@kasparkallas hmm. Would it help if you checked |
Looks like that is indeed the case... 😛 Thank you very much, sir! |
Uh oh!
There was an error while loading. Please reload this page.
I'd like to see an easy way to reset the query to uninitialized without having to re-mount the component.
Example usage:
Passing the
skipOrResetToken
guarantees that there's no data (i.e. stale data) coming from the query.The use-case arose from the fact that the stale data with just the
skipToken
can be surprising when you have a user inputted conditional for whether to execute the query or not (e.g. "address", "item name", "username" etc).The text was updated successfully, but these errors were encountered: