Feature Flag Determination

๐Ÿ“˜

Feature flags are only available for SDK version 2.0.0 or higher.

When using feature flags, please apply SDK version 2.0.0 or higher when adding dependencies.

A feature flag has an on and off state. You will set different features according to each state.

Once a feature flag is applied, a specific user from your traffic should be able to either receive an off or on status. This on/off status determination can be done through the Hackle SDK.

useFeature

You can use the Hooks API provided by Hackle to receive status results for the user. At this time, you need to pass the feature key, and then implement the logic according to each on/off status.

In the example code below, we are passing feature key 42.

function App() {
  return (
    // Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
    // For undetermined cases, users are assigned to false (off status). 
    <Feature featureKey={42}>
      {(featureOn) =>
        featureOn ? (
          <SuperAwesomeFeature /> // Logic for on status
        ) : (
          <AwesomeFeature /> // Logic for off status
        )
      }
    </Feature>
  )
}
function App() {
    // Determines the status of the feature flag to assign the user in a feature flag with a feature key of 42.
    // For undetermined cases, users are assigned to false (off status). 
  const featureOn = useFeature(42)
  return (
    <>
    {
      featureOn ? (
        <SuperAwesomeFeature /> // Logic for on status
      ) : (
        <AwesomeFeature /> // Logic for off status
      )
    }
    </>
  )
}

useFeatureFlagDetail

The useFeatureFlagDetail() Hooks API works the same as useFeature() but additionally provides a reason for determining the status of a particular user. This can be useful when you want to check whether the manual allocation is working well or when you think that the traffic allocation you have set is not being reflected in your results.

You must pass a function key as a parameter. For the example code below, we are passing function key 42.

// Status determination details
const decision = useFeatureFlagDetail(42)

// Feature flag on/off results 
const isOn = decision.isOn

// Reason for status determination
const reason = decision.reason

Please refer to the table below for the full list of reasons for different status determinations.

ReasonDescriptionFeature Status
SDK_NOT_READYThe SDK is not ready to use.
(e.g. Initialization with the wrong SDK key)
Default status(off)
EXPERIMENT_NOT_FOUNDNo feature flags were found for the feature key you passed.
The feature key may be incorrect or the corresponding feature flag may be in an archived state.
Default status(off)
OVERRIDDENThe user has been determined to have a specific feature flag status by manual assignment.Manual assignment
TRAFFIC_ALLOCATEDUser status has been determined.Status determined
INVALID_INPUTThe input value is not valid.
(e.g. A letter type was inputting in a parameter that requires a numeric type)
Default status(off)
EXCEPTIONAn unknown error has occurred.Default status(off)