createHook - Workflows SDK Reference

This documentation provides a reference to the createHook . It belongs to the Workflows SDK.

Expose a hook in your workflow where you can inject custom functionality as a step function.

A handler hook can later be registered to consume the hook and perform custom functionality.

Learn more in this documentation.

Example#

Code
1import {2  createStep,3  createHook,4  createWorkflow,5  WorkflowResponse,6} from "@medusajs/framework/workflows-sdk"7import { createProductStep } from "./steps/create-product"8
9export const myWorkflow = createWorkflow(10  "my-workflow",11  function (input) {12    const product = createProductStep(input)13    const productCreatedHook = createHook(14      "productCreated",15      { productId: product.id }16    )17
18    return new WorkflowResponse(product, {19      hooks: [productCreatedHook],20    })21  }22)

Type Parameters#

NamestringOptional
TInvokeInputobjectOptional

Parameters#

nameName
The hook's name. This is used when the hook handler is registered to consume the workflow.
inputTInvokeInput
The input to pass to the hook handler.

Returns#

HookHook<Name, TInvokeInput>
A workflow hook.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break