CollectionHooksInput
Defined in: packages/core/src/collections/hooks.ts:91
Lifecycle hooks for a collection. beforeChange/beforeDelete run inline
in the write path and may reject a write by throwing. afterChange/
afterDelete run via convex-helpers triggers, after the write commits,
through the mutation builder returned by createVexMutations — they never
run for a write made through the raw _generated/server builder, the
Convex dashboard, or npx convex import.
Each method is generic over TDataModel (not fixed to the interface’s own
type params) so a dispatch call site — collection.hooks.beforeChange({ ctx: realCtx, ... }) — infers TDataModel fresh from the real ctx it
passes in, with no cast: GenericMutationCtx<ConcreteDataModel> is
otherwise not assignable to GenericMutationCtx<GenericDataModel> at all
(Convex’s index-query builder is invariant across DataModel
instantiations), the same reason validateFields is generic over
TDataModel rather than fixed. Author a hook inline (contextual
typing — hooks: { beforeChange: async ({ doc, ctx }) => ... }) or via
beforeChangeHook/beforeDeleteHook/afterChangeHook/afterDeleteHook;
an extracted, explicitly-BeforeChangeProps<...>-annotated function is the
one authoring style this does NOT accept (its own ctx type is pinned to
GenericDataModel, not generic per assignment).
Type Parameters
Section titled “Type Parameters”TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends CollectionSlug = CollectionSlug
Methods
Section titled “Methods”afterChange()?
Section titled “afterChange()?”
optionalafterChange<TDataModel>(props):void|Promise<void>
Defined in: packages/core/src/collections/hooks.ts:98
Type Parameters
Section titled “Type Parameters”TDataModel
Section titled “TDataModel”TDataModel extends GenericDataModel = GenericDataModel
Parameters
Section titled “Parameters”AfterChangeProps<TCollectionSlug, TDataModel>
Returns
Section titled “Returns”void | Promise<void>
afterDelete()?
Section titled “afterDelete()?”
optionalafterDelete<TDataModel>(props):void|Promise<void>
Defined in: packages/core/src/collections/hooks.ts:101
Type Parameters
Section titled “Type Parameters”TDataModel
Section titled “TDataModel”TDataModel extends GenericDataModel = GenericDataModel
Parameters
Section titled “Parameters”AfterDeleteProps<TCollectionSlug, TDataModel>
Returns
Section titled “Returns”void | Promise<void>
beforeChange()?
Section titled “beforeChange()?”
optionalbeforeChange<TDataModel>(props):TDocument|Promise<TDocument>
Defined in: packages/core/src/collections/hooks.ts:92
Type Parameters
Section titled “Type Parameters”TDataModel
Section titled “TDataModel”TDataModel extends GenericDataModel = GenericDataModel
Parameters
Section titled “Parameters”BeforeChangeProps<TCollectionSlug, TDataModel>
Returns
Section titled “Returns”TDocument | Promise<TDocument>
beforeDelete()?
Section titled “beforeDelete()?”
optionalbeforeDelete<TDataModel>(props):void|Promise<void>
Defined in: packages/core/src/collections/hooks.ts:95
Type Parameters
Section titled “Type Parameters”TDataModel
Section titled “TDataModel”TDataModel extends GenericDataModel = GenericDataModel
Parameters
Section titled “Parameters”BeforeDeleteProps<TCollectionSlug, TDataModel>
Returns
Section titled “Returns”void | Promise<void>