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

text-fields.tsx

24 lines652 Bytes

1import { For } from 'solid-js'
2import { useStore } from '@tanstack/solid-form'
3import { useFieldContext } from '../hooks/form-context.tsx'
4​
5export default function TextField(props: { label: string }) {
6 const field = useFieldContext<string>()
7​
8 const errors = useStore(field().store, (state) => state.meta.errors)
9​
10 return (
11 <div>
12 <label>
13 <div>{props.label}</div>
14 <input
15 value={field().state.value}
16 onChange={(e) => field().handleChange(e.target.value)}
17 />
18 </label>
19 <For each={errors()}>
20 {(error) => <div style={{ color: 'red' }}>{error}</div>}
21 </For>
22 </div>
23 )