Skip to content

Function: next()

next<Value>(value): Ctx<Value>

Defined in: packages/action/src/helpers.ts:24

Creates a context object for passing data between middleware functions.

Type Parameters

Value

Value extends object = { }

The object type to be merged into the context. Properties will be available to subsequent middleware and actions.

Parameters

value

Value = ...

Value that will be merged to the next context value object

Returns

Ctx<Value>

A context object that can be returned by middleware functions

Example

typescript
const action = createAction()
  .with(async () => {
    return next({ session: await getSession() });
  })
  .with(async ({ ctx }) => {
    return next({ user: await getUser(ctx.session.userId) });
  })
  .with(({ ctx }) => {
    console.log(ctx); // { session: { userId: string }, user: { name: string, ... } }
    return next();
  })
  .do(({ ctx }) => {...});