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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With