You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing so, the query invalidation runs before we navigate away from the detail page of the deleted item. Thus it tries to refetch it and receives a 404.
Because of the retry, it retries multiple times before abandonning and finally doing the navigation. So the delete button remains multiple seconds in loading state before navigating, which is a bad UX.
Non-solutions
Removing await from invalidateQueries:
There may be multiple places where this mutation wrapper hook is called, and they may want to benefit from the awaited query invalidation to avoid showing stale data.
Add a custom callback onBeforeInvalidate at the hook level
This is not ideal because the flow is less easy to read: mutation and navigation are in two different places. Also the mutateAsync function is not reusable without navigation in the same component. What'd be more ideal is the solution proposed below.
Proposal
Add a callback onBeforeSuccess at the mutation level:
I didn't think of the naming for too long, so the naming and the API probably would need to be challenged (what about errors too?). But generally, this motivates to have more fine grained options at the mutation level to hook into the lifecycle of query then invalidation.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have the following use-case:
useItem(someId)
The problem
When doing so, the query invalidation runs before we navigate away from the detail page of the deleted item. Thus it tries to refetch it and receives a 404.
Because of the retry, it retries multiple times before abandonning and finally doing the navigation. So the delete button remains multiple seconds in loading state before navigating, which is a bad UX.
Non-solutions
await
from invalidateQueries:There may be multiple places where this mutation wrapper hook is called, and they may want to benefit from the awaited query invalidation to avoid showing stale data.
onBeforeInvalidate
at the hook levelThis is not ideal because the flow is less easy to read: mutation and navigation are in two different places. Also the mutateAsync function is not reusable without navigation in the same component. What'd be more ideal is the solution proposed below.
Proposal
Add a callback
onBeforeSuccess
at the mutation level:I didn't think of the naming for too long, so the naming and the API probably would need to be challenged (what about errors too?). But generally, this motivates to have more fine grained options at the mutation level to hook into the lifecycle of query then invalidation.
Beta Was this translation helpful? Give feedback.
All reactions