-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathreact-hook-form-demo.tsx
54 lines (49 loc) · 1.27 KB
/
react-hook-form-demo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use client";
import * as React from "react";
import { z } from "zod";
import { FileUploader } from "~/components/file-uploader";
import { Button } from "~/components/ui/button";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
useForm,
} from "~/components/ui/form";
export function ReactHookFormDemo() {
const form = useForm({
schema: z.object({
images: z.array(z.instanceof(File)),
}),
});
const onSubmit = form.handleSubmit((input) => {});
return (
<Form {...form}>
<form onSubmit={onSubmit} className="flex w-full flex-col gap-6">
<FormField
control={form.control}
name="images"
render={({ field }) => (
<div className="space-y-6">
<FormItem className="w-full">
<FormLabel>Images</FormLabel>
<FormControl>
<FileUploader
files={field.value}
onFilesChange={field.onChange}
/>
</FormControl>
<FormMessage />
</FormItem>
</div>
)}
/>
<Button className="w-fit" disabled={form.formState.isSubmitting}>
Save
</Button>
</form>
</Form>
);
}