This hook retrieves the configuration values for a macro. Note that the configuration data is loaded asynchronously, so its output will be undefined
while it is still loading.
Use configuration to store general data, but not sensitive information. The configuration data is stored in plaintext, so other users and apps can access and modify the values.
To add the useConfig
hook to your app:
1 2import { useConfig } from "@forge/react";
Here is an example of accessing configuration for a Forge macro. Note that you'll need to add configuration to the Confluence macro module in order to configure the displayed values.
1 2import React from 'react'; import ForgeReconciler, { Heading, Text, Textfield, useConfig } from '@forge/react'; const defaultConfig = { name: 'Unnamed Pet', age: '0' }; const App = () => { const config = useConfig() || defaultConfig; // Displaying a pet's name and age using the configuration values. return ( <> <Heading as="h1">Content with configured values</Heading> <Text>"{config.name}" is "{config.age}" years old.</Text> </> ); }; // Function that defines the configuration UI for the pet's name and age const Config = () => { return ( <> <Textfield name="name" label="Pet name" defaultValue={defaultConfig.name} /> <Textfield name="age" label="Pet age" defaultValue={defaultConfig.age} /> </> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> ); // Adding the Config function to the ForgeReconciler to allow for configuration changes ForgeReconciler.addConfig(<Config />);
1 2interface ExtensionConfiguration { [key: string]: any; } function useConfig(): ExtensionConfiguration | undefined;
None.
MacroConfig
component. If the macro has not yet been configured, this hook returns undefined
.Rate this page: