Hi! What would be the best way to determine if a f...
# contributing
n
Hi! What would be the best way to determine if a feature flag is disabled when fetching feature flags from the API (
<https://cdn.growthbook.io/api/features/[key]>
)? Is it safe to assume that
defaultValue
is always set to
null
for a disabled feature?
It would be nice to have an
enabled
boolean property, and include the
rules
array for all feature flags, regardless if they're enabled or not.
f
Yea, there's no perfect way right now to differentiate the enabled state. If a feature is disabled for an environment, it will be set to
{"defaultValue": null}
with no rules. However, it's possible for a feature to be "enabled" in the environment, but still have the default value set to null and no rules.
What is your specific use case where you need to identify the disabled features?
n
I see! I'll filter by
defaultValue
then, and always make sure to set a default value for enabled features. We're integrating Growthbook with Sanity Studio to be able to deploy A/B tests without pushing any code. To avoid having to copy-paste the name of a feature flag from Growthbook to Sanity, I'm creating a custom select component that is pre-populated with the currently enabled feature flags.
f
ok, that makes sense. We were thinking of just removing disabled features from the JSON response entirely (the default for unknown features is
null
anyway, so the behavior is the same).
c
+1 to removing them from the JSON response (if you are looking for validation on that) ^ on tangible benefit is that we would not leak upcoming features as they are being developed on in dev
n
@future-teacher-7046 That would make more sense to me as well!
f
I just pushed this change. Disabled features are no longer included in the API response
🙌 1
c
woo, awesome!