Skip to content

beforeChangeHook

beforeChangeHook<TCollectionSlug, TDataModel>(slug, fn): (<TDataModel>(props) => TDocument | Promise<TDocument>) | undefined

Defined in: packages/core/src/collections/hooks.ts:125

Types a collection’s beforeChange hook against a real collection, DataModel, and resolved CollectionConfig, without touching BeforeChangeProps directly. TCollectionSlug is inferred from slug; supply TDataModel explicitly for a typed ctx.

TCollectionSlug extends string

TDataModel extends GenericDataModel = GenericDataModel

TCollectionSlug

The collection slug doc/collection should be typed as — pass the same constant the collection itself is defineCollection({ slug })-ed with (e.g. TABLE_SLUG_PAGES), not a fresh string literal, so a rename of one renames the other.

(props) => TDocument | Promise<TDocument>

The hook function, checked against the real types.

(<TDataModel>(props) => TDocument | Promise<TDocument>) | undefined

The same function, re-typed to the collection’s loose public hooks.beforeChange signature.