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

formContext.ts

17 lines461 Bytes

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