Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

771 B
Raw Blame
import { useValues } from 'kea'

import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'

export const useFeatureFlag = (flag: keyof typeof FEATURE_FLAGS, match?: string): boolean => {
    const { featureFlags } = useValues(featureFlagLogic)

    // If a match is provided, we're only actually gonna check it if not running on Storybook
    // On storybook we'll simply set the flag to be available and in that case we just ignore the match
    // and check the flag itself
    if (match && !inStorybook() && !inStorybookTestRunner()) {
        return featureFlags[FEATURE_FLAGS[flag]] === match
    }

    return !!featureFlags[FEATURE_FLAGS[flag]]
}