Skip to content

Instantly share code, notes, and snippets.

@prokizzle
Last active July 14, 2021 00:55
Show Gist options
  • Save prokizzle/1fa573d78e510282c74089c6b120d3f8 to your computer and use it in GitHub Desktop.
Save prokizzle/1fa573d78e510282c74089c6b120d3f8 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;
@yungwarlock
Copy link

This is a marvelous piece. Thank you very much for teaching this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment