All files / react-app/src/hooks useFeatureFlag.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18      77x 186x   186x 183x     3x         3x    
import { useLDClient } from "launchdarkly-react-client-sdk";
import { featureFlags } from "shared-utils";
 
export const useFeatureFlag = (flagKey: keyof typeof featureFlags): boolean => {
  const ldClient = useLDClient();
 
  if (!ldClient) {
    return false;
  }
 
  const flagValue = ldClient?.variation(
    featureFlags[flagKey].flag,
    featureFlags[flagKey].defaultValue,
  );
 
  return flagValue === "on" || flagValue === true;
};