Skip to content

Instantly share code, notes, and snippets.

@yungwarlock
Forked from prokizzle/ExampleComponent.js
Created July 14, 2021 00:55
Show Gist options
  • Save yungwarlock/e9593c865ee39b8e79158e40ea4e5702 to your computer and use it in GitHub Desktop.
Save yungwarlock/e9593c865ee39b8e79158e40ea4e5702 to your computer and use it in GitHub Desktop.
useFeatureFlag Example
import React from 'react';
import useFeatureFlag from './useFeatureFlag';
import RecommendationsComponent from './Recommendations.js';
const {
DecoratedComponent: Recommendations,
featureEnabled: recommendationsFeatureEnabled,
FeatureFlag
} = useFeatureFlag({
Component: RecommendationsComponent,
feature: 'RECOMMENDATIONS'
});
const ExampleComponent = () => {
const pageTitle = recommendationsFeatureEnabled ? 'Recommendations' : 'Saved Items';
return <div>
<h1>{pageTitle}</h1>
<Recommendations />
<FeatureFlag>
<Dependency recommendations={recommendations} />
</FeatureFlag>
</div>;
};
import React from 'react';
const Recommendations = ({ featureEnabled }) => {
if (!featureEnabled) {
return <div>Page Not Found</div>
}
return <div>
<h1>Recommendations</h1>
<div>{recommendations}</div>
</div>;
}
export default Recommendations;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment