MCPcopy Create free account
hub / github.com/cosdensolutions/code / App

Function App

videos/long/react-hook-form-tutorial/src/App.tsx:12–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10type FormFields = z.infer<typeof schema>;
11
12const App = () => {
13 const {
14 register,
15 handleSubmit,
16 setError,
17 formState: { errors, isSubmitting },
18 } = useForm<FormFields>({
19 defaultValues: {
20 email: "test@email.com",
21 },
22 resolver: zodResolver(schema),
23 });
24
25 const onSubmit: SubmitHandler<FormFields> = async (data) => {
26 try {
27 await new Promise((resolve) => setTimeout(resolve, 1000));
28 console.log(data);
29 } catch (error) {
30 setError("root", {
31 message: "This email is already taken",
32 });
33 }
34 };
35
36 return (
37 <form className="tutorial gap-2" onSubmit={handleSubmit(onSubmit)}>
38 <input {...register("email")} type="text" placeholder="Email" />
39 {errors.email && (
40 <div className="text-red-500">{errors.email.message}</div>
41 )}
42 <input {...register("password")} type="password" placeholder="Password" />
43 {errors.password && (
44 <div className="text-red-500">{errors.password.message}</div>
45 )}
46 <button disabled={isSubmitting} type="submit">
47 {isSubmitting ? "Loading..." : "Submit"}
48 </button>
49 {errors.root && <div className="text-red-500">{errors.root.message}</div>}
50 </form>
51 );
52};
53
54export default App;

Callers

nothing calls this directly

Calls 1

handleSubmitFunction · 0.50

Tested by

no test coverage detected