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