Loading...
Loading...
Add feature flags to an application for gradual rollouts, A/B testing, and kill switches using PostHog, LaunchDarkly, or a simple local implementation.
npx skill4agent add spencerpauly/awesome-cursor-skills adding-feature-flagsnpm install posthog-jsimport { useFeatureFlagEnabled } from "posthog-js/react";
function MyComponent() {
const showNewFeature = useFeatureFlagEnabled("new-checkout-flow");
if (showNewFeature) return <NewCheckout />;
return <OldCheckout />;
}import { PostHog } from "posthog-node";
const posthog = new PostHog(process.env.POSTHOG_API_KEY!);
const isEnabled = await posthog.isFeatureEnabled("new-checkout-flow", userId);lib/feature-flags.tsexport const FLAGS = {
NEW_CHECKOUT: process.env.NEXT_PUBLIC_FF_NEW_CHECKOUT === "true",
DARK_MODE: process.env.NEXT_PUBLIC_FF_DARK_MODE === "true",
} as const;import { FLAGS } from "@/lib/feature-flags";
function App() {
return FLAGS.NEW_CHECKOUT ? <NewCheckout /> : <OldCheckout />;
}.env.env.exampleNEXT_PUBLIC_FF_NEW_CHECKOUT=false
NEXT_PUBLIC_FF_DARK_MODE=truenew-checkout-flowflag-1