Open History to see the last commit
1import type { FormApi } from '@tanstack/form-core'
2import { inject, provide } from 'vue-demi'
3β
4export type FormContext = {
5 formApi: FormApi<any, unknown>
6 parentFieldName?: string
7} | null
8β
9export const formContext = Symbol('FormContext')
10β
11export function provideFormContext(val: FormContext) {
12 provide(formContext, val)
13}
14β
15export function useFormContext() {
16 const formApi = inject(formContext) as FormContext
17β
18 if (!formApi) {
19 throw new Error(`You are trying to use the form API outside of a form!`)
20 }
21β
22 return formApi
23}