Last active
July 14, 2021 00:55
-
-
Save prokizzle/1fa573d78e510282c74089c6b120d3f8 to your computer and use it in GitHub Desktop.
useFeatureFlag Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This is a marvelous piece. Thank you very much for teaching this.