Last active
November 13, 2025 00:04
-
-
Save isocroft/551d99f5152cc8d471ab3c21be5f108d to your computer and use it in GitHub Desktop.
A simple use of a feature flag hook where the 1st rule of hooks in ReactJS is seemingly broken but not broken at all
This file contains hidden or 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
| function useXFeature (user, { xFeatureName = "", pageAndSection = "." } = {}) { | |
| /* @NOTE: | |
| This `useFeatureFlagConfig(...)` is static an immutable. | |
| It can't change/be updated at runtime. | |
| */ | |
| const { isEnabledFor, loading } = useFeatureToggle(user); | |
| if (isEnabledFor(xFeatureName, pageAndSection)) { | |
| return useXFeature_Newer_Implementation_Stable(); | |
| } | |
| /* @HINT: | |
| The env variable is replaced by a hardcoded value | |
| at build time (using Webpack DefinePlugin). | |
| It can't chnage/be updated at runtime either. | |
| */ | |
| else if (process.env.EXPERIMENTAL_X_FEATURE_ENABLED) { | |
| return useXFeature_Experimental_Implementation_Unstable(); | |
| } else { | |
| return useXFeature_Legacy_Implementation_Stable(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment