Skip to content

getCollectionDefaultValues

getCollectionDefaultValues(props): Record<string, unknown>

Defined in: packages/core/src/collections/utils.ts:29

Builds the defaultValues object for a TanStack Form instance from a collection.

When document is provided, uses the document’s field values (edit mode). When omitted, falls back to each field’s defaultValue (create mode). The returned object’s keys match the collection field keys.

Input props.

CollectionConfig

The collection whose fields define the form shape.

TDocument | null

Optional existing document to populate values from when editing.

Record<string, unknown>

A Record<fieldKey, value> ready to pass to useForm({ defaultValues }).

// New document — uses field defaults
getCollectionDefaultValues({ collection: postsCollection })
// → { title: "", slug: "" }
// Existing document — uses document values
getCollectionDefaultValues({ collection: postsCollection, document: doc })
// → { title: "Hello world", slug: "hello-world" }