Open History to see the last commit
1import { useFieldContext } from '../AppForm'
2β
3export function TextField({ label }: { label: string }) {
4 // The `Field` infers that it should have a `value` type of `string`
5 const field = useFieldContext<string>()
6 return (
7 <label>
8 <span>{label}</span>
9 <input
10 value={field.state.value}
11 onChange={(e) => field.handleChange(e.target.value)}
12 onBlur={() => field.handleBlur()}
13 />
14β
15 <>
16 {field.state.meta.isTouched && !field.state.meta.isValid ? (
17 <em>{field.state.meta.errors.join(',')}</em>
18 ) : null}
19 {field.state.meta.isValidating ? 'Validating...' : null}
20 </>
21 </label>
22 )
23}