MCPcopy Index your code
hub / github.com/react-hook-form/react-hook-form / IsValid

Function IsValid

app/src/isValid.tsx:17–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15 .required();
16
17const 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 />

Callers

nothing calls this directly

Calls 4

useFormFunction · 0.85
unregisterFunction · 0.85
handleSubmitFunction · 0.85
registerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…