Open History to see the last commit
1import { formOptions } from '@tanstack/form-core'
2import { createInternalForm } from '../SolidFormApi.lib'
3import { defineFieldGroup } from '../FieldGroup/withFields.public'
4import { createAppFormInitializer } from './initializeAppForm.lib'
5import { useFormContext } from './contexts.lib'
6import type {
7 AppFormHookResult,
8 CreateFormHookOptions,
9 UseAppFormHook,
10} from './createFormHookTypes.public'
11import type { Accessor, Component } from 'solid-js'
12import type { FormOptions } from '@tanstack/form-core'
13β
14export function createFormHook<
15 const TFormComponents extends Record<string, Component<any>>,
16 const TFieldComponents extends Record<string, Component<any>>,
17>(
18 createOptions: CreateFormHookOptions<TFormComponents, TFieldComponents>,
19): AppFormHookResult<{
20 formComponents: TFormComponents
21 fieldComponents: TFieldComponents
22}> {
23 const initializeAppForm = createAppFormInitializer(createOptions)
24β
25 function useExtendedForm(
26 options: Accessor<FormOptions<any, any, any, unknown>>,
27 ) {
28 return createInternalForm(options, initializeAppForm)
29 }
30 const useAppForm = useExtendedForm as never as UseAppFormHook<{
31 formComponents: TFormComponents
32 fieldComponents: TFieldComponents
33 }>
34β
35 return {
36 useFormContext: useFormContext as never,
37 appFormOptions: formOptions as never,
38 defineAppFieldGroup: defineFieldGroup as never,
39 useAppForm,
40 }
41}