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

formOptions.md

49 lines1.4 KB

1---
2id: formOptions
3title: formOptions
4---
5​
6```ts
7const formOptions: FormOptionsApi<unknown>;
8```
9​
10Defined in: [utils.public.ts:373](https://github.com/TanStack/form/blob/main/packages/form-core/src/utils.public.ts#L373)
11​
12Keeps form data, validator, and submission types inferred when options are
13declared separately from a framework's form creation API.
14​
15The regular helper takes `defaultValues` at face value as the form data
16shape. For schema-driven inference, use `formOptions.strictSchema` when the
17schema defines an input-to-output boundary, or `formOptions.looseSchema` when
18the schema defines the shape but editable defaults may omit properties or
19need `null` or `undefined` values.
20​
21At runtime, this is an identity helper: it returns the original options
22object and does not create a form or run validation.
23​
24## Remarks
25​
26**Important:** Although this returns the original object unchanged at
27runtime, its type is normalized to `FormOptions`. Optional properties such
28as `validators` therefore remain optional even when supplied. This tradeoff
29enables safer inference and reuse.
30​
31## Example
32​
33```ts
34const profileOptions = formOptions({
35 defaultValues: { name: '' },
36 validators: [
37 {
38 triggers: ['change'],
39 run: ({ value }) =>
40 value.name.length === 0 ? 'Name is required' : undefined,
41 },
42 ],
43})
44​
45const form = useForm({
46 ...profileOptions,
47 onSubmit: ({ value }) => saveProfile(value),
48})
49```