-
Book Overview & Buying
-
Table Of Contents
React Application Architecture for Production - Second Edition
By :
Feature flags are a way to control which users see which features at runtime without deploying new code. Instead of releasing a feature to everyone at once, we wrap it in a flag check. The flag is off by default. We can turn it on for internal users first, then a small percentage of real users, then everyone.
This has a few important benefits. It decouples deployment from release, so we can merge code early without exposing incomplete features. It makes rollbacks instant; if something goes wrong, we flip the flag rather than reverting a deploy.
For a small number of flags, we can start with environment variables or a simple database table. A flag is just a boolean we check before rendering something:
// src/lib/flags.ts
export const flags = {
newIdeaDashboard: import.meta.env.VITE_FLAG_NEW_IDEA_DASHBOARD === 'true',
};
// src/components/dashboard.tsx
import { flags } from "@/lib/flags";
function Dashboard...