onSettled of useMutation getting called before onSettled of call-site mutate function #4845
-
I need the onSettled callback that gets passed into the call site of the mutate function to happen before the onSettled callback that is defined in the base useMutation hook. Is there a way to achieve this? Currently they execute in the reverse order: base hook onSettled, then call-site onSettled. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi 👋 No, there's no way to achieve this. The callbacks passed to Please see: https://tkdodo.eu/blog/mastering-mutations-in-react-query#some-callbacks-might-not-fire |
Beta Was this translation helpful? Give feedback.
-
What is the reason for having the base-hook callbacks execute before the call-site callbacks? If the call-site callbacks happened first, then it would allow the developer to choose the order by using |
Beta Was this translation helpful? Give feedback.
Hi 👋
No, there's no way to achieve this. The callbacks passed to
useMutation
will always fire before the callbacks passed tomutate
. Be aware that there are also situations in which callbacks passed tomutate
might not fire at all.Please see: https://tkdodo.eu/blog/mastering-mutations-in-react-query#some-callbacks-might-not-fire