Skip to content

blocks

blocks<TCollectionSlug, TFieldKey, TFieldMeta>(options): BlocksField<TCollectionSlug, TFieldMeta>

Defined in: packages/core/src/fields/blocks/config.ts:103

Creates a blocks field with all defaults applied.

Validates that all block slugs are unique within this field. Each item stored in Convex carries blockType, blockName, and id in addition to the block’s own fields.

TCollectionSlug extends string = string

TFieldKey extends string = never

TFieldMeta extends BaseFieldMeta = BaseFieldMeta

BlocksFieldInput<TCollectionSlug, TFieldKey, TFieldMeta>

Blocks field configuration. blocks is required.

BlocksField<TCollectionSlug, TFieldMeta>

Resolved blocks field definition.

If two or more block definitions share the same slug.

const heading = defineBlock({ slug: "heading", label: "Heading", fields: { text: text({ required: true }) } })
const paragraph = defineBlock({ slug: "paragraph", label: "Paragraph", fields: { content: text({ required: true }) } })
defineCollection({
fields: {
body: blocks({
label: "Body",
blocks: [heading, paragraph],
labels: { singular: "section", plural: "sections" },
}),
},
})