Prerequisites
What are prerequisites?
Section titled “What are prerequisites?”A prerequisite is a condition you attach to a feature flag that says: “only evaluate this flag if another flag is already ON (or has a specific value).”
This lets you build dependency chains:
checkout-v2only activates ifnew-payment-provideris ON.ai-search-resultsonly activates ifsearch-redesignis ON andbeta-featuresis ON.
Without prerequisites, you have to manage these dependencies manually in your application code — adding if (flagA && flagB) guards everywhere. Prerequisites move that logic into GrowthBook, keeping your code clean and making the dependency visible in the UI.
When to use prerequisites
Section titled “When to use prerequisites”Prerequisites are most useful when:
- Staged rollout chains — a surface-level flag depends on an infrastructure flag being fully rolled out first.
- Kill switches with dependencies — turning off
new-payment-providershould automatically deactivate everything that depends on it, without an engineering deploy. - Beta gate stacking — a feature is only accessible if the user is in both a general
betacohort AND a specific sub-experiment.
Creating a prerequisite in the GrowthBook UI
Section titled “Creating a prerequisite in the GrowthBook UI”- Navigate to Features and open the feature you want to add a prerequisite to (the dependent flag).
- On the feature detail page, click Edit next to Default Value & Rules.
- Scroll to the Prerequisites section and click Add Prerequisite.
- In the dropdown, search for and select the parent flag (the one that must be ON first).
- Set the Required Value — for a boolean flag, choose
true. - Click Save.
Now, when the SDK evaluates the dependent flag:
- If the parent flag is
false(or its override rules returnfalse), the dependent flag returns its off value regardless of its own rules. - If the parent flag is
true, the dependent flag evaluates normally.
Important: Circular prerequisites (A requires B, B requires A) are detected and blocked by GrowthBook at save time.
Dependency chain example
Section titled “Dependency chain example”Imagine three features in sequence:
new-payment-provider (infrastructure flag) ↓ prerequisite checkout-v2 (UI flag) ↓ prerequisite express-checkout (premium surface flag)Turning off new-payment-provider cascades — both checkout-v2 and express-checkout go dark automatically, even if their own rules say ON. This gives you a single kill switch for the entire chain.
import { GrowthBook } from '@growthbook/growthbook';
const gb = new GrowthBook({
apiHost: 'https://cdn.growthbook.io',
clientKey: 'sdk-YOUR_DEV_KEY',
attributes: { id: 'user-123' },
});
await gb.init({ timeout: 2000 });
// Prerequisites are evaluated server-side in GrowthBook
// and baked into the feature payload the SDK downloads.
// No extra client code is needed — isOn() already
// respects the prerequisite chain.
const paymentOn = gb.isOn('new-payment-provider');
const checkoutOn = gb.isOn('checkout-v2'); // false if paymentOn is false
const expressOn = gb.isOn('express-checkout'); // false if checkoutOn is false
console.log({ paymentOn, checkoutOn, expressOn });