Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 545 Bytes

03.HOC-feature-toggles.md

File metadata and controls

23 lines (18 loc) · 545 Bytes

HOC for Feature Toggles

Using Higher order components (HOC) for UX variations

eg. Toggling features On/Off

// featureToggle.js
const isFeatureOn = function (featureName) {
  // return true or false
};

import { isFeatureOn } from './featureToggle';

const toggleOn = (featureName, ComposedComponent) => class HOC extends Component {
  render() {
    return isFeatureOn(featureName) ? <ComposedComponent {...this.props} /> : null;
  }
};

// Usage
import AdsComponent from './Ads'
const Ads = toggleOn('ads', AdsComponent);