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

form.tsx

30 lines779 Bytes

1import { createFormHook, getFormHookHelpers } from '@tanstack/react-form'
2import { TextField } from '../components/text-fields.tsx'
3​
4const { fieldComponent } = getFormHookHelpers()
5​
6const AppTextField = fieldComponent.strict(TextField, 'field')
7​
8function SubscribeButton({ label }: { label: string }) {
9 const form = useFormContext()
10 return (
11 <form.Subscribe selector={(state) => state.isSubmitting}>
12 {(isSubmitting) => (
13 <button type="submit" disabled={isSubmitting}>
14 {label}
15 </button>
16 )}
17 </form.Subscribe>
18 )
20​
21const { appFormOptions, useAppForm, useFormContext } = createFormHook({
22 fieldComponents: {
23 TextField: AppTextField,
24 },
25 formComponents: {
26 SubscribeButton,
27 },
28})
29​
30export { appFormOptions, useAppForm }