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.
To add the useProductContext
hook to your app:
1 2import { useProductContext } from "@forge/react";
Here is an example of an app that displays all its context information with useProductContext
.
1 2import 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> );
1 2function 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; }
None.
undefined
for free apps, apps not listed on the Atlassian Marketplace, and apps in development and staging environments. See the LicenseDetails
type for what information is available.manifest.yml
file.Rate this page: