codecret | Software EngineerC
tRPC11mo ago
15 replies
codecret | Software Engineer

invalidate query

whenever i add a user my user list is not updating

 const mutation = trpc.user.addUser.useMutation();

  async function onSubmit(values: z.infer<typeof formSchema>) {
    await mutation.mutateAsync(values);
    router.push("/admin/all-employees");
  }


does not get updated
 const { data: users, isLoading } = trpc.user.getUsers.useQuery(undefined, {
    refetchOnMount: false,
    refetchOnReconnect: false,
  });


what i have tried :

const mutation = trpc.user.addUser.useMutation(["addUser"]);

searched for invalidate query but couldn't know how to setup a mutation key and invalidate it

caused an error
Type 'string[]' has no properties in common with type 'UseTRPCMutationOptions<{ name: string; email: string; username: string; password: string; role: string; }, TRPCClientErrorLike<{ input: { name: string; email: string; username: string; password: string; role: string; }; output: { user: { name: string; ... 9 more ...; | undefined;...'.ts(2559)
Was this page helpful?