Open History to see the last commit
1import { createContext, useContext } from 'solid-js'
2import type { FormApi, Validator } from '@tanstack/form-core'
3β
4type FormContextType =
5 | undefined
6 | {
7 formApi: FormApi<any, Validator<any, unknown> | undefined>
8 parentFieldName?: string
9 }
10β
11export const formContext = createContext<FormContextType>(undefined)
12β
13export function useFormContext() {
14 const formApi: FormContextType = useContext(formContext)
15β
16 if (!formApi)
17 throw new Error(`You are trying to use the form API outside of a form!`)
18β
19 return formApi
20}