Best practice
Hey there! I was wondering if there was a better way of doing this:
export function useCancelSubscription() {
const queryClient = useQueryClient();
return useMutation(['subscription'], ({ subscriptionId }: any) => cancelSubscription(subscriptionId), {
onSuccess: (subscription) => {
queryClient.setQueryData(['guilds', { subscribed: true }], (guilds: OAuth2Guild[]) => {
const index = guilds.findIndex(({ id }) => id == subscription.billableId);
guilds[index].subscription = subscription;
return guilds;
});
},
});
}
export function useCancelSubscription() {
const queryClient = useQueryClient();
return useMutation(['subscription'], ({ subscriptionId }: any) => cancelSubscription(subscriptionId), {
onSuccess: (subscription) => {
queryClient.setQueryData(['guilds', { subscribed: true }], (guilds: OAuth2Guild[]) => {
const index = guilds.findIndex(({ id }) => id == subscription.billableId);
guilds[index].subscription = subscription;
return guilds;
});
},
});
}
0 Replies