How can I add dynamic values to default values in useForm?

22 views Asked by At

I have two types of accounts, each with different features: 'star' and 'follower.' In my useForm on the settings component, both account types share some default fields. However, for the 'star' account type, there are additional fields with default values specific to them. I'm currently encountering a TypeScript error when attempting the following:

  const {
    register,
    getValues,
  } = useForm({
    defaultValues: {
      imgurl: imgUrl,
      displayName: displayName,
      email: email,
      descirption: descirption,
    },
  });


return (

<>

 {celeb && (
                      <>
                      <input
                      
                      {...register("job")} //ts error here
                      />
)}

</>


error: Argument of type '"job"' is not assignable to parameter of type '"imgurl" | "displayName" | "email" | "descirption"'

the docs recommend you don't use undefined values.

Thats all.

0

There are 0 answers