isSuccess correct value to check response in trpc?

Hello I am wondering if isSuccess is the proper value which I should check once I call my mutation. Sometimes the function inside the isSuccess condition does not run, even if my mutation was successful. Any idea how to improve that?
const {
isLoading,
error,
isSuccess,
mutate: createClient,
} = trpc.client.create.useMutation()

const onSubmit: SubmitHandler<CreateClientInput> = async (data) => {
createClient(data)
if (isSuccess) {
toast.success('Success.')
// router.push('/clients')
}
if (error) toast.error('An error occured.')
}
const {
isLoading,
error,
isSuccess,
mutate: createClient,
} = trpc.client.create.useMutation()

const onSubmit: SubmitHandler<CreateClientInput> = async (data) => {
createClient(data)
if (isSuccess) {
toast.success('Success.')
// router.push('/clients')
}
if (error) toast.error('An error occured.')
}
10 Replies
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
utdev
utdevOP•3y ago
so what the difference between isSuccess on onSuccess confuses me 😄
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
utdev
utdevOP•3y ago
you sure there is a onSuccess method?
const {
isLoading,
error,
isSuccess,
onSuccess, // can not find it
mutate: createClient,
} = trpc.client.create.useMutation()
const {
isLoading,
error,
isSuccess,
onSuccess, // can not find it
mutate: createClient,
} = trpc.client.create.useMutation()
'onSuccess' is declared but its value is never read.ts(6133)
Property 'onSuccess' does not exist on type 'UseMutationResult<{ data: { company: Company | undefined; client: Customer | undefined; bankAccount: BankAccount | undefined; }; },
'onSuccess' is declared but its value is never read.ts(6133)
Property 'onSuccess' does not exist on type 'UseMutationResult<{ data: { company: Company | undefined; client: Customer | undefined; bankAccount: BankAccount | undefined; }; },
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
utdev
utdevOP•3y ago
ohh
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
utdev
utdevOP•3y ago
Got it like this then
createClient(data, {
onSuccess: () => {
toast.success('Client created')
router.push('/clients')
},
onError: (error) => {
toast.error(error.message)
}
})
createClient(data, {
onSuccess: () => {
toast.success('Client created')
router.push('/clients')
},
onError: (error) => {
toast.error(error.message)
}
})
But still not sure if I need to use await
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
utdev
utdevOP•3y ago
ty 🙂
Want results from more Discord servers?
Add your server