T
TanStack2y ago
stormy-gold

Sveltekit - $mutation.isSuccess stays true indefinitely after submit

As the title suggests isSuccess will stay true indefinitely after a createMutation call regardless of whether I invalidate in onSuccess or onSettled callbacks. The isPending works, but I feel like it goes false before the queries are invalidated. (I could be wrong though) It might not make a difference at all, but I was just wondering if I need to do something in my createMutation call to trigger the isSuccess parameter? Thanks in advance for any help you can provide.
10 Replies
other-emerald
other-emerald2y ago
You can reset the query Also await your onSuccess actions
stormy-gold
stormy-goldOP2y ago
Nailed it. AWAIT. I am invalidating the query, but the isSuccess param is still always true
fair-rose
fair-rose2y ago
I don't think invalidate puts those flags into their original state. Maybe you want reset instead
stormy-gold
stormy-goldOP2y ago
I am fine with is pending as your advice works perfectly for me with isPending oh is there a rest? *reset let me look. Thanks hmm. .resetQueries() causes full page refresh for me and does not trigger inSuccess
fair-rose
fair-rose2y ago
What are you trying to invalidate? A separate query in your mutation onSuccess?
stormy-gold
stormy-goldOP2y ago
Ahh.
fair-rose
fair-rose2y ago
According to the React docs useMutation, which I think is nearly identical to your createMutation, it returns a reset method to "A function to clean the mutation internal state (i.e., it resets the mutation to its initial state)."
stormy-gold
stormy-goldOP2y ago
Your the man. I didnt cancel the other queries in onMutate Cool ya. There is a reset but that's in the UI and wouldn't help in the createMutation call But ya iam good. Really appreciate it. Thanks
fair-rose
fair-rose2y ago
So sounds like you're good to go now?
stormy-gold
stormy-goldOP2y ago
Thanks again

Did you find this page helpful?