-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLocationForm.tsx
52 lines (48 loc) · 1.26 KB
/
LocationForm.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
import { useForm, Controller } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup";
import { Button, FormWrapper, Input } from "../devlink";
const schema = yup
.object({
location: yup.string().required("Please enter a location."),
})
.required();
export const LocationForm = () => {
const {
handleSubmit,
control,
formState: { errors },
} = useForm({
defaultValues: {
location: "",
},
resolver: yupResolver(schema),
});
return (
<form onSubmit={handleSubmit((data) => console.log(JSON.stringify(data)))}>
<FormWrapper
formBody={
<>
<Controller
name="location"
control={control}
render={({ field }) => (
<Input
isError={!!errors.location}
errorMessage={errors.location?.message}
inputProps={{
...field,
placeholder: "Seattle, WA",
type: "text",
"aria-invalid": errors.location ? "true" : "false",
}}
/>
)}
/>
<Button />
</>
}
></FormWrapper>
</form>
);
};