UI Kit components
Jira UI Kit components
UI Kit hooks
Forge bridge APIs
Jira bridge APIs
Upgrade UI Kit versions
Previous versions

useProductContext

This hook reads the context in which the component is currently running. Note that the context data is loaded asynchronously, so its output will be undefined while it is still loading.

Usage

To add the useProductContext hook to your app:

1
2
import { useProductContext } from "@forge/react";

Here is an example of an app that displays all its context information with useProductContext.

The app display on a Confluence page

1
2
import React from 'react';
import ForgeReconciler, { Code, Heading, Text, useProductContext } from '@forge/react';

const App = () => {
  const context = useProductContext();

  return (<>
    <Heading as="h3">Product context</Heading>
    <Text>
      Module key from context:
      <Code>{context?.moduleKey}</Code>
    </Text>
  </>);
};

ForgeReconciler.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

Function signature

1
2
function useProductContext(): ProductContext | undefined;

interface ProductContext {
  accountId?: string;
  cloudId?: string;
  workspaceId?: string;
  extension: ExtensionData;
  license?: LicenseDetails;
  localId: string;
  locale: string;
  moduleKey: string;
  siteUrl: string;
  timezone: string;
  theme?: {
    colorMode: string;
    light: string;
    dark: string;
    spacing: string;
    [key:string]: string;
  };
}

interface ExtensionData {
  [k: string]: any;
}

interface LicenseDetails {
  active: boolean;
  billingPeriod: string;
  ccpEntitlementId: string;
  ccpEntitlementSlug: string;
  isEvaluation: boolean;
  subscriptionEndDate: string | null;
  supportEntitlementNumber: string | null;
  trialEndDate: string | null;
  type: string;
}

Arguments

None.

Returns

Rate this page: