Skip to content

Instantly share code, notes, and snippets.

@isocroft
Last active November 13, 2025 00:04
Show Gist options
  • Select an option

  • Save isocroft/551d99f5152cc8d471ab3c21be5f108d to your computer and use it in GitHub Desktop.

Select an option

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
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