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
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
Share
Improve this question
edited Apr 2, 2022 at 18:30
jonrsharpe
122k30 gold badges268 silver badges476 bronze badges
asked Apr 2, 2022 at 18:23
Bishal GiriBishal Giri
412 silver badges2 bronze badges
1
- 1 Please give a minimal reproducible example. Take the tour, read How to Ask. – jonrsharpe Commented Apr 2, 2022 at 18:27
1 Answer
Reset to default 6you 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)