()
| 15 | .required(); |
| 16 | |
| 17 | const IsValid: React.FC = () => { |
| 18 | const { mode, defaultValues } = useParams(); |
| 19 | const isBuildInValidation = mode === 'build-in'; |
| 20 | const [show, setShow] = React.useState(true); |
| 21 | const { |
| 22 | register, |
| 23 | handleSubmit, |
| 24 | unregister, |
| 25 | formState: { isValid }, |
| 26 | } = useForm<{ |
| 27 | firstName: string; |
| 28 | lastName: string; |
| 29 | hidden: string; |
| 30 | age: string; |
| 31 | location: string; |
| 32 | select: string; |
| 33 | radio: string; |
| 34 | checkbox: string; |
| 35 | }>({ |
| 36 | mode: 'onChange', |
| 37 | ...(isBuildInValidation ? {} : { resolver: yupResolver(validationSchema) }), |
| 38 | ...(defaultValues === 'defaultValues' |
| 39 | ? { |
| 40 | defaultValues: { |
| 41 | firstName: 'test', |
| 42 | lastName: 'test1', |
| 43 | }, |
| 44 | } |
| 45 | : {}), |
| 46 | }); |
| 47 | |
| 48 | React.useEffect(() => { |
| 49 | if (isBuildInValidation) { |
| 50 | if (show) { |
| 51 | unregister('hidden'); |
| 52 | } |
| 53 | } else { |
| 54 | if (!show) { |
| 55 | unregister('firstName'); |
| 56 | } |
| 57 | } |
| 58 | }, [show, isBuildInValidation, unregister]); |
| 59 | |
| 60 | renderCounter++; |
| 61 | |
| 62 | return ( |
| 63 | <form onSubmit={handleSubmit(() => {})}> |
| 64 | {isBuildInValidation ? ( |
| 65 | <> |
| 66 | <input {...register('location')} placeholder="location" /> |
| 67 | <input |
| 68 | {...register('firstName', { required: true })} |
| 69 | placeholder="firstName" |
| 70 | /> |
| 71 | <input |
| 72 | {...register('lastName', { required: true })} |
| 73 | placeholder="lastName" |
| 74 | /> |
nothing calls this directly
no test coverage detected
searching dependent graphs…