TanStackT
TanStack2y ago
14 replies
primary-violet

useMutation invalidateQueries does not trigger either on onSuccess or onSettled

Please is there anything i might be doing wrong because after the successful mutation it doesnt refetch the data

  const { mutate, isPending } = useMutation({
    mutationFn: (value: { companyName: string }) => {
      return updateClient({ value, clientNo })
    },
    onSuccess: () => {
      toast.success('Cient has been successfuly Updated.')
      setEdit(false)
      queryClient.invalidateQueries({
        queryKey: ['client', clientNo]
      })
    },
    onSettled: () => {
      queryClient.invalidateQueries({
        queryKey: ['client', clientNo]
      })
    },
    onError: (error) => {
      const custom = error as CustomError
      toast.error(`${custom?.response?.data}`)
    }
  })

  const onSubmit = async (values: z.infer<typeof clientEditFormSchema>) => {
    mutate(values)
  }
Was this page helpful?