@carbon/ibm-products
Version:
Carbon for IBM Products
37 lines (33 loc) • 1.27 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
require("../../../_virtual/_rolldown/runtime.js");
let react = require("react");
let _carbon_react = require("@carbon/react");
//#region src/global/js/hooks/useCarbonFeatureFlagsObject.ts
/**
* Copyright IBM Corp. 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Custom hook that converts Carbon's FeatureFlags scope to a plain object.
* This is useful when you need to pass parent feature flags to a nested
* FeatureFlags component, ensuring all parent flags are preserved.
*
* @returns {Record<string, boolean>} An object containing all feature flags from the parent scope
*/
function useCarbonFeatureFlagsObject() {
const parentFeatureFlags = (0, _carbon_react.unstable_useFeatureFlags)();
return (0, react.useMemo)(() => {
const flagsObj = {};
if (parentFeatureFlags?.flags) for (const [key, value] of parentFeatureFlags.flags) flagsObj[key] = value;
return flagsObj;
}, [parentFeatureFlags]);
}
//#endregion
exports.useCarbonFeatureFlagsObject = useCarbonFeatureFlagsObject;