@harnessio/ff-react-client-sdk
Version:
[![React version][react-badge]][reactjs] [![TypeScript version][ts-badge]][typescript-4-7] [![Node.js version][nodejs-badge]][nodejs] [![APLv2][license-badge]][license]
21 lines (20 loc) • 968 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { FFContext } from '../context/FFContext';
export function ifFeatureFlag(flagName, { matchValue = undefined, loadingFallback = null } = {}) {
return function ifFeatureFlagHoc(WrappedComponent) {
return (props) => (_jsx(FFContext.Consumer, { children: ({ client, loading }) => {
if (loading) {
return loadingFallback;
}
const internalNoValue = 'FF_SDK_INTERNAL_NO_VALUE';
const flagValue = client === null || client === void 0 ? void 0 : client.variation(flagName, internalNoValue);
if (matchValue === flagValue ||
(matchValue === undefined &&
flagValue !== internalNoValue &&
!!flagValue)) {
return _jsx(WrappedComponent, { ...props });
}
return null;
} }));
};
}