tRPCttRPC
Powered by
PeformP
tRPC•17mo ago•
1 reply
Peform

onSuccess mutation not being called

Hey, I have this mutation which is called when I click a button. Inside the
onSuccess
onSuccess
callback I show a toast to the user telling them that the request was successful. However, when I do a state change before I call the mutation, eg
setRequests
setRequests
the
onSuccess
onSuccess
callback never runs, I know this because the console log never appears. But, when I remove the
setRequests
setRequests
it does, there is no visible error in my console. Why does this happen? Is it by design?
export const GenerationsCard = ({ generation, selectedFlag, setRequests }: Props) => {
    const clearMutation = api.generations.clear.useMutation();
    const warnMutation = api.punishments.warn.useMutation();
    const banMutation = api.punishments.ban.useMutation();

    const handleBanGeneration = async (requestId: string, requestType: string) => {
        setRequests((prev) => prev?.filter((req) => req.id !== requestId));
        await banMutation.mutateAsync(
            { requestId, requestType },
            {
                onSuccess: (response) => {
                    console.log(234243243);
                    toast('Success', {
                        description: response.message,
                        action: {
                            label: 'Undo',
                            onClick: () => console.log('Undo'),
                        },
                    });
                },
                onError: (error) => {},
            },
        );
    };
export const GenerationsCard = ({ generation, selectedFlag, setRequests }: Props) => {
    const clearMutation = api.generations.clear.useMutation();
    const warnMutation = api.punishments.warn.useMutation();
    const banMutation = api.punishments.ban.useMutation();

    const handleBanGeneration = async (requestId: string, requestType: string) => {
        setRequests((prev) => prev?.filter((req) => req.id !== requestId));
        await banMutation.mutateAsync(
            { requestId, requestType },
            {
                onSuccess: (response) => {
                    console.log(234243243);
                    toast('Success', {
                        description: response.message,
                        action: {
                            label: 'Undo',
                            onClick: () => console.log('Undo'),
                        },
                    });
                },
                onError: (error) => {},
            },
        );
    };
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

errorFormatter is not being called?
lunacraftsLlunacrafts / ❓-help
4y ago
onSuccess invalidate
Alex GomesAAlex Gomes / ❓-help
3y ago
onSuccess not triggered when route changes
Answer OverflowAAnswer Overflow / ❓-help
2y ago
onSuccess with createTRPCProxyClient
BillyBobBBillyBob / ❓-help
2y ago