AWIXOR
AWIXOR

Reputation: 542

RTK: How to run refetch after mutation success

I want to call refetch function after the mutation succeded:

 const [joinTeam ] = useJoinTeamMutation();
 const { refetch } = useGetTeam(slugName);

I tried doing:

joinTeam().then((res: any) => {
     if (!res.error) {
          refetch();
     }
});

but this causes an error: Cannot refetch a query that has not been started yet.

Upvotes: 0

Views: 369

Answers (1)

Shocky
Shocky

Reputation: 167

This is builtin using tags, no need for promises check the docs Automatic refetch

Upvotes: 1

Related Questions