Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type '{ name: string; email: string; password: string; }' is not assignable to parameter of type 'void'

I am using React Query with TypeScript.

Mutation:

   let mutation = useMutation((newUser) => {
      return signup(newUser)
   })

Submit function:

const onSignupSubmit = ({ name, email, password }: User) => {
      mutation.mutate(
          {
            name,
            email,
            password,
         }
      )
   }

Also this line giving me error:

mutation?.error?.response?.data?.field
like image 489
Bishal Giri Avatar asked Oct 16 '25 21:10

Bishal Giri


1 Answers

you need to define the type of the mutation function passed to useMutation:

let mutation = useMutation((newUser: User) => {
    return signup(newUser)
})

a shorter way would be to omit the arrow function and just do:

let mutation = useMutation(signup)
like image 124
TkDodo Avatar answered Oct 18 '25 14:10

TkDodo