Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error for useMutation #4

Open
hasanaktas opened this issue Aug 24, 2024 · 0 comments
Open

Typescript error for useMutation #4

hasanaktas opened this issue Aug 24, 2024 · 0 comments

Comments

@hasanaktas
Copy link

import { api } from "@backend/convex/_generated/api";
import { useMutation } from "@tanstack/react-query";
import { useConvexMutation } from "@convex-dev/react-query";


  const mutation = useMutation({
    mutationFn: useConvexMutation(api.explore.react),

    onSuccess: async (data) => {
    
    },
    onError: async (error) => {
     
    },
  });

If I use it as specified in the document, there is no problem. However, when I try to access the API variables, TypeScript gets angry. The type of the variables is void.

import { api } from "@backend/convex/_generated/api";
import { useMutation } from "@tanstack/react-query";
import { useConvexMutation } from "@convex-dev/react-query";


  const mutation = useMutation({
    mutationFn: useConvexMutation(api.explore.react),

    onSuccess: async (data,variables) => {
    
    },
    onError: async (error,variables) => {
     
    },
  });

As a solution, if I create mutationFn as an external variable, typescript does not give an error and the type of the variables is shown correctly.

import { api } from "@backend/convex/_generated/api";
import { useMutation } from "@tanstack/react-query";
import { useConvexMutation } from "@convex-dev/react-query";


  const mutationFn = useConvexMutation(api.explore.react);

  const mutation = useMutation({
    mutationFn: mutationFn,

    onSuccess: async (data,variables) => {
    
    },
    onError: async (error,variables) => {
     
    },
  });

err1
err2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant