Core or custom integrations
Build a form without a UI framework
TanStack · Class
FormApi is TanStack Form’s core class for managing form state, validation, and submission. Framework adapters usually create it through hooks or factory functions, but it can be constructed directly when needed.
FormApi is the core class that owns form state and coordinates interactions such as value updates, validation, and submission. Framework adapters normally create it for you; instantiate it directly when you need a framework-independent form instance.
new FormApi(options)| Name | Type | Description |
|---|---|---|
options | FormOptions<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta> | Options used to configure the new form instance, including its state, validation, and submission behavior. |
A configured FormApi instance.
import { FormApi } from '@tanstack/form-core'
const form = new FormApi({
defaultValues: { email: '' },
onSubmit: async ({ value }) => {
console.log(value.email)
},
})
form.mount()
form.setFieldValue('email', 'dev@example.com')
await form.handleSubmit()
form.dispose()Creates a core form, updates a field, submits the current values, and disposes the instance.
Build a form without a UI framework
Use a framework adapter that creates the underlying instance
Own form state, validation, and submission in a custom abstraction
FormApi is the core form class responsible for form-state logic and interactions. It supports reading and updating state, validation, and submission, while framework adapters add framework-specific behavior.
Follow-up: Why should an application usually avoid constructing it directly? Framework hooks or factory functions create an instance integrated with the framework's reactivity model.
Construct it with form options by calling the FormApi constructor. The options configure the instance, including the initial form behavior and submission handling.
Follow-up: When would manual construction be appropriate? Use it when a framework-independent or otherwise custom FormApi instance is needed.
FormApi is framework-agnostic core functionality. React or other adapters compose it with framework-specific helpers rather than changing the core form-state responsibilities.
Follow-up: What does an adapter add? It supplies the framework integration needed for reactive updates and framework-oriented APIs.
FormOptionsReactFormApiReactFormExtendedApiAnyFormApiFormValidators