()
| 5 | let renderCounter = 0; |
| 6 | |
| 7 | const Basic: React.FC = () => { |
| 8 | const { mode } = useParams(); |
| 9 | const [data, setData] = React.useState({}); |
| 10 | const { |
| 11 | register, |
| 12 | handleSubmit, |
| 13 | formState: { errors }, |
| 14 | reset, |
| 15 | } = useForm<{ |
| 16 | firstName: string; |
| 17 | lastName: string; |
| 18 | min: string; |
| 19 | max: string; |
| 20 | minDate: string; |
| 21 | maxDate: string; |
| 22 | minLength: string; |
| 23 | minRequiredLength: string; |
| 24 | selectNumber: string; |
| 25 | pattern: string; |
| 26 | radio: string; |
| 27 | checkbox: string; |
| 28 | checkboxArray: string[]; |
| 29 | multiple: string; |
| 30 | validate: string; |
| 31 | nestItem: { |
| 32 | nest1: string; |
| 33 | }; |
| 34 | arrayItem: { test1: string; test2: string }[]; |
| 35 | }>({ |
| 36 | mode: mode as keyof ValidationMode, |
| 37 | }); |
| 38 | const [onInvalidCalledTimes, setOnInvalidCalledTimes] = useState(0); |
| 39 | const onInvalid = () => setOnInvalidCalledTimes((prevCount) => prevCount + 1); |
| 40 | |
| 41 | renderCounter++; |
| 42 | |
| 43 | return ( |
| 44 | <form |
| 45 | onSubmit={handleSubmit((data) => { |
| 46 | setData(data); |
| 47 | }, onInvalid)} |
| 48 | > |
| 49 | <input |
| 50 | placeholder="nestItem.nest1" |
| 51 | {...register('nestItem.nest1', { required: true })} |
| 52 | /> |
| 53 | {errors.nestItem?.nest1 && <p>nest 1 error</p>} |
| 54 | <input |
| 55 | placeholder="arrayItem[0].test1" |
| 56 | {...register('arrayItem.0.test1', { required: true })} |
| 57 | /> |
| 58 | {errors.arrayItem?.[0]?.test1 && <p>array item 1 error</p>} |
| 59 | <input |
| 60 | {...register('firstName', { required: true })} |
| 61 | placeholder="firstName" |
| 62 | /> |
| 63 | {errors.firstName && <p>firstName error</p>} |
| 64 | <input |
nothing calls this directly
no test coverage detected