UNPKG

@launchdarkly/react-native-client-sdk

Version:
62 lines 2.4 kB
import useLDClient from '../useLDClient'; /** * Determines the strongly typed variation of a feature flag. * * @param key The unique key of the feature flag. * @param defaultValue The default value of the flag, to be used if the value is not available * from LaunchDarkly. * @returns * The strongly typed value. */ export const useTypedVariation = (key, defaultValue) => { const ldClient = useLDClient(); switch (typeof defaultValue) { case 'boolean': return ldClient.boolVariation(key, defaultValue); case 'number': return ldClient.numberVariation(key, defaultValue); case 'string': return ldClient.stringVariation(key, defaultValue); case 'undefined': case 'object': return ldClient.jsonVariation(key, defaultValue); default: return ldClient.variation(key, defaultValue); } }; /** * Determines the strongly typed variation of a feature flag for a context, along with information about * how it was calculated. * * The `reason` property of the result will also be included in analytics events, if you are * capturing detailed event data for this flag. * * If the flag variation does not have the specified type, defaultValue is returned. The reason will * indicate an error of the type `WRONG_KIND` in this case. * * For more information, see the [SDK reference * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native). * * @param key The unique key of the feature flag. * @param defaultValue The default value of the flag, to be used if the value is not available * from LaunchDarkly. * @returns * The result (as an {@link LDEvaluationDetailTyped<T>}). */ export const useTypedVariationDetail = (key, defaultValue) => { const ldClient = useLDClient(); switch (typeof defaultValue) { case 'boolean': return ldClient.boolVariationDetail(key, defaultValue); case 'number': return ldClient.numberVariationDetail(key, defaultValue); case 'string': return ldClient.stringVariationDetail(key, defaultValue); case 'undefined': case 'object': return ldClient.jsonVariationDetail(key, defaultValue); default: return ldClient.variationDetail(key, defaultValue); } }; //# sourceMappingURL=useTypedVariation.js.map