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
fascinating-indigo•2y ago
You can reset the query
Also await your onSuccess actions
sunny-greenOP•2y ago
Nailed it. AWAIT.
I am invalidating the query, but the
isSuccess param is still always trueoptimistic-gold•2y ago
I don't think invalidate puts those flags into their original state. Maybe you want reset instead
sunny-greenOP•2y 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 inSuccessoptimistic-gold•2y ago
What are you trying to invalidate? A separate query in your mutation
onSuccess?sunny-greenOP•2y ago
Ahh.
optimistic-gold•2y 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)."sunny-greenOP•2y 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. Thanksoptimistic-gold•2y ago
So sounds like you're good to go now?
sunny-greenOP•2y ago
Thanks again