React input boolean value in default value
P粉148782096
P粉148782096 2023-09-10 14:11:36
0
1
514

I have a controlled checkbox input and I am supposed to set the default value on request but I am getting the error "Type 'boolean' is not assignable to type 'string | number | readonly string[] | undefined'". Maybe you know how to avoid this?

<input
   {...register("car")}
   type="checkbox"
   defaultValue={data.car ? true : false}
/>

P粉148782096
P粉148782096

reply all(1)
P粉019353247

You can use the defaultChecked attribute on input elements.

For example:

<input
  {...register("car")}
  type="checkbox"
  defaultChecked={data.car ? true : false}
/>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template