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

form.tsx

25 lines678 Bytes

1import { createFormHook } from '@tanstack/react-form'
2import { lazy } from 'react'
3import { fieldContext, formContext, useFormContext } from './form-context.tsx'
4​
5const TextField = lazy(() => import('../components/text-fields.tsx'))
6​
7function SubscribeButton({ label }: { label: string }) {
8 const form = useFormContext()
9 return (
10 <form.Subscribe selector={(state) => state.isSubmitting}>
11 {(isSubmitting) => <button disabled={isSubmitting}>{label}</button>}
12 </form.Subscribe>
13 )
15​
16export const { useAppForm, withForm } = createFormHook({
17 fieldComponents: {
18 TextField,
19 },
20 formComponents: {
21 SubscribeButton,
22 },
23 fieldContext,
24 formContext,
25})