The useTheme hook retrieves the current theme from the Atlassian app (Jira, Confluence, etc.) and reactively updates your Forge app when the theme changes. This is the preferred way to access theme information in UI Kit apps, rather than accessing theme.colorMode via useProductContext.
To add the useTheme hook to your app:
1 2import { useTheme } from "@forge/react";
Here is an example of using the useTheme hook to access theme information:
1 2import React from "react"; import ForgeReconciler, { useTheme, Heading, Text } from "@forge/react"; const App = () => { const theme = useTheme(); if (!theme) { return <Text>Loading theme...</Text>; } return ( <> <Heading as="h1">Current Theme</Heading> <Text>Color mode: {theme.colorMode}</Text> </> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> );
1 2type Theme = { colorMode: string; light: string; dark: string; spacing: string; [key: string]: string; }; function useTheme(): Theme | null;
None.
Rate this page: