In this tutorial, you'll add a feature flag to a Forge app, create the flag in Developer Console, and see it toggle a UI element on and off — without redeploying your app.
What you'll build: A flag that shows or hides a premium welcome message.
What you'll learn:
Time: 10 minutes
You need:
Install the server-side SDK:
1 2cd your-forge-app npm install @forge/feature-flags@latest
Update your resolver to initialize the SDK and check a flag. Replace your src/resolvers/index.js:
1 2// src/resolvers/index.js import Resolver from '@forge/resolver'; import { FeatureFlags } from "@forge/feature-flags"; const resolver = new Resolver(); resolver.define('getFlagValue', async ({ payload, context }) => { const featureFlags = new FeatureFlags(); await featureFlags.initialize({ environment: context?.environmentType?.toLowerCase() || "development" }); const user = { identifiers: { installContext: context?.installContext }, attributes: { installContext: context?.installContext } }; return featureFlags.checkFlag(user, payload?.flag, false); }); export const handler = resolver.getDefinitions();
Update your frontend to call the resolver and show the message. Replace your src/frontend/index.jsx:
1 2// src/frontend/index.jsx import React, { useEffect, useState } from 'react'; import ForgeReconciler, { Text } from '@forge/react'; import { invoke } from '@forge/bridge'; const App = () => { const [showPremium, setShowPremium] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { invoke('getFlagValue', { flag: 'show_premium_welcome' }) .then((value) => { setShowPremium(value); setLoading(false); }) .catch(() => { setShowPremium(false); setLoading(false); }); }, []); if (loading) { return <Text>Loading...</Text>; } return ( <> <Text>Hello world!</Text> {showPremium && ( <Text appearance="success">Welcome to Premium Features!</Text> )} </> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> );
1 2forge deploy forge install --upgrade
The app now contains feature flag code, but the flag doesn't exist yet — it defaults to false.
show premium welcomeControls premium welcome message visibilityinstallContextThe Flag ID (show_premium_welcome) is automatically generated from the name.
100% and Fail to 0%Refresh your app — You should now see the "Welcome to Premium Features!" message.
Toggle it off:
show_premium_welcome0%, Fail to 100% → SaveToggle it back on:
100%, Fail 0% → SaveYou've just controlled a feature without redeploying your app.
@forge/feature-flags) initializes in your resolvercheckFlag(user, flagId, defaultValue) returns true or false based on your flag configurationfalse when they don't exist yet — safe to deploy code before creating the flagRate this page: