Feature Gating: How We Built a Freemium SaaS Without Duplicating Components
dev.to·2d·
Discuss: DEV
🔧Code Refactoring Patterns
Preview
Report Post

The problem with most feature-gating implementations? They end up scattering billing checks throughout your codebase like landmines. You’ve got if (user.plan === 'pro') everywhere, making it impossible to test components in isolation or understand what features are actually gated.

Here’s how we solved it with a FeatureGate component that wraps restricted features instead of modifying them.

The Problem

We needed to add subscription tiers to our analytics dashboard. Some features should show upgrade prompts on free plans, others should be completely hidden. But we didn’t want to:

  • Touch every component that needs restrictions
  • Break existing tests
  • Make components aware of billing logic
  • Duplicate UI for "locked" states

The Solution: A Wrapper Component

Instead of …

Similar Posts

Loading similar posts...