API Reference > @next-core/brick-kit > useFeatureFlags
useFeatureFlags() function
显示特性开关
Signature:
export declare function useFeatureFlags(
name?: string | string[]
): boolean[] | string[];
Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | string[] | 特性开关名称 |
Returns:
boolean[] | string[]
boolean[] | string[]
Example
featureFlags = { "enabled-foo": true, "enabled-bar": true };
function MyReactComponent(props) {
// 返回所有的特性开关名称数组
const featureFlags = useFeatureFlags();
console.log(featureFlags);
// Output: ["enabled-foo", "enabled-bar"]
// ...
}
featureFlags = { "enabled-foo": true };
function MyReactComponent(props) {
// 返回传入的特性开关名布尔值数组
const [isEnabledFoo, isEnabledBar] = useFeatureFlags([
"enabled-foo",
"enabled-bar",
]);
console.log([isEnabledFoo, isEnabledBar]);
// Output: [true, false]
// ...
}