I have a mutate function which make POST request and receives id , after then I need Immediately call next mutation function to make a purchase in accordance with this id, how do I make this ?
const mutation = useCreatePaymentMethodMutation();
const handleSubmit = async(values:any) {
const form = await mutation.mutateAsync({
values,
hash
})
return form
}
useCreatePaymentMethodMutation is imported from @Hooks
const useCreatePaymentMethodMutation = () => {
return useMutation(
({ values, accessHash }: { values: any; accessHash: string }) =>
createPaymentMethodRequest(values, accessHash),
{
onSuccess: (data) => {
// usePayMutation(data.data, accessHash); error. I need to use data after 1st mutation in next
request
console.log("on success data ", data);
},
}
);
}
UPD 1
Here is my usePayMutation method
const usePayMutation = () => {
return useMutation(({ data, id }: { data: any; id: string }) =>
payRequest(data, id)
);
};