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 size="small">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(): FullContext | undefined;

interface FullContext {
  accountId?: string;
  cloudId?: string;
  workspaceId?: string;
  extension: ExtensionData;
  license?: LicenseDetails;
  localId: string;
  locale: string;
  moduleKey: string;
  siteUrl: string;
  timezone: 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: