最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Argument of type '{ name: string; email: string; password: string; }' is not assignable to paramete

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

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)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论