@umbraco-cms/backoffice
    Preparing search index...

    Function consumeContext

    • A property decorator that adds an UmbContextConsumerController to the component which will try and retrieve a value for the property via the Umbraco Context API.

      This decorator supports both modern "standard" decorators (Stage 3 TC39 proposal) and legacy TypeScript experimental decorators for backward compatibility.

      The consumer is registered directly via addUmbController, relying on the host's own lifecycle to fire hostConnected before first render. No Lit ReactiveController wrapper is needed — UmbControllerHostMixin lazy-inits its controllers list, so addUmbController is safe during addInitializer.

      Type Parameters

      Parameters

      Returns ConsumeDecorator<ResultType>

      A property decorator function

      import {consumeContext} from '@umbraco-cms/backoffice/context-api';
      import {UMB_WORKSPACE_CONTEXT} from './workspace.context-token.js';

      class MyElement extends UmbLitElement {
      // Standard decorators (with 'accessor' keyword) - Modern approach
      @consumeContext({context: UMB_WORKSPACE_CONTEXT})
      accessor workspaceContext?: UmbWorkspaceContext;

      // Legacy decorators (without 'accessor') - Works with @state/@property
      @consumeContext({context: UMB_USER_CONTEXT, subscribe: false})
      @state()
      currentUser?: UmbUserContext;
      }