Feature Flag Decision
A Feature Flag has two states: on and off. Different features are configured for each state. When a user accesses a feature with a Feature Flag applied, the SDK must return the on or off state. You can use the Hackle SDK to determine this state.
useFeature or useLoadableFeature
You can receive the state result for a user using the Hooks API provided by Hackle. You must pass the Feature Key, then implement logic based on the state.
In the example code below, Feature Key 42 is passed.
function App() {
return (
// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
<Feature featureKey={42}>
{(featureOn) =>
featureOn ? (
<SuperAwesomeFeature /> // 켜짐 상태일 때의 기능
) : (
<AwesomeFeature /> // 꺼짐 상태일 때의 기능
)
}
</Feature>
)
}function App() {
// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
const featureOn = useFeature(42)
return (
<>
{
featureOn ? (
<SuperAwesomeFeature /> // 켜짐 상태일 때의 기능
) : (
<AwesomeFeature /> // 꺼짐 상태일 때의 기능
)
}
</>
)
}
// Loadable 사용 시
function App() {
// 기능 키가 42인 기능 플래그에서 사용자의 상태를 결정합니다.
// 결정하지 못하는 상황인 경우 false(꺼짐 상태)를 반환합니다.
const { loaded, result } = useLoadableFeature(42)
return (
<>
{
result ? (
<SuperAwesomeFeature /> // 켜짐 상태일 때의 기능
) : (
<AwesomeFeature /> // 꺼짐 상태일 때의 기능
)
}
</>
)
}useFeatureFlagDetail or useLoadableFeatureDetail
The useFeatureFlagDetail() Hooks API works the same as useFeature() but also provides the reason for the state decision. This is useful for verifying that Override is working correctly or when the distribution result ratio seems inconsistent with the configured Traffic Allocation.
You must pass the Feature Key as a parameter. In the example code below, Feature Key 42 is passed.
The state decision reason is returned in the format SDK_NOT_READY. See the table below for details.
SDK_NOT_READY
The SDK is not ready to use. (e.g., initialization attempted with an invalid SDK Key)
Default state (off)
FEATURE_FLAG_NOT_FOUND
No Feature Flag was found for the provided Feature Key. The Feature Key may be incorrect, or the Feature Flag may be archived.
Default state (off)
FEATURE_FLAG_INACTIVE
The Feature Flag is in the off state.
Default state (off)
INDIVIDUAL_TARGET_MATCH
Matched by Individual Targeting.
State configured by Individual Targeting
TARGET_RULE_MATCH
Matched by User Targeting.
State configured by User Targeting
DEFAULT_RULE
Did not match either Individual Targeting or User Targeting.
State configured by default rule
EXCEPTION
An unknown error occurred.
Default state (off)
Feature Flag Parameters
You can also receive the parameter values for the state decision via the
useFeatureFlagDetail()Hooks API.You can use the config object and
getSync()method to retrieve the Parameter Settings configured on the Feature Flag screen. If you change the value on the Feature Flag parameter settings screen, the updated value is applied to your code.
The
parameterKeyin thegetSync()method is the key configured in the Feature Flag parameter settings, anddefaultValueis the value returned when state decision fails or an incorrect parameter type value is provided.To correctly retrieve the configured value, you must enter a value of the same type as the parameter type you configured in
defaultValue.JSON type can be received as a string (String), so the
defaultValuefor JSON type must be entered as a string type.The parameter types provided by the SDK are string, number, and boolean. The JSON type configured on the Feature Flag screen can be received as a string (String). The default value for JSON type must be entered as a string type.
Last updated