๐ด Live Demo
Feature Flag Testing
Feature Component Output:
โ Feature Enabled: Theme Switcher
Dynamic theme switching functionality
This content is only visible when the feature flag is enabled!
Note: If you don't see the green success box above, the selected feature is disabled in the configuration.
โ๏ธ Feature Flags Configuration
Features Configuration
// config/Features.yml
features:
sampleFeature:
enabled: true
description: 'A sample feature for demonstration'
rolloutPercentage: 100
environment: ['development', 'production']
betaFeature:
enabled: false
description: 'Experimental beta functionality'
rolloutPercentage: 25
environment: ['development']
newDashboard:
enabled: true
description: 'New dashboard interface'
rolloutPercentage: 75
environment: ['development', 'staging']
๐ฏ Common Use Cases
๐งช A/B Testing
- Test different UI components
- Compare user engagement
- Gradual feature rollout
- Performance comparison
๐ Beta Features
- Early feature access
- User feedback collection
- Risk mitigation
- Incremental deployment
๐๏ธ Development
- Work-in-progress features
- Environment-specific content
- Debug information
- Developer tools
โจ Key Features
๐๏ธ Control & Flexibility
- YAML-based configuration
- Runtime feature toggling
- Environment-specific settings
- Percentage-based rollouts
- Easy feature management
โก Performance & UX
- Zero-overhead when disabled
- No runtime feature detection
- Clean component wrapping
- Conditional rendering only
- Build-time optimization
๐ป Usage Examples
Basic Feature Gating
import FeatureComponent from '@site/src/components/FeatureComponent';
export default function MyPage() {
return (
<Layout>
<h1>My Page</h1>
{/* Always visible content */}
<p>This content is always visible</p>
{/* Feature-gated content */}
<FeatureComponent feature='newDashboard'>
<div className='new-dashboard'>
<h2>New Dashboard (Beta)</h2>
<p>This is only visible when newDashboard feature is enabled</p>
</div>
</FeatureComponent>
</Layout>
);
}
Conditional Navigation
// In navigation components
import FeatureComponent from '@site/src/components/FeatureComponent';
export default function Navigation() {
return (
<nav>
<Link to='/home'>Home</Link>
<Link to='/about'>About</Link>
<FeatureComponent feature='betaFeatures'>
<Link to='/beta'>Beta Features</Link>
</FeatureComponent>
<FeatureComponent feature='adminPanel'>
<Link to='/admin'>Admin Panel</Link>
</FeatureComponent>
</nav>
);
}
๐ Related Resources
Learn more about feature flags and conditional rendering