Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

TextField.tsx

23 lines672 Bytes

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 )