Files
explore/lib/growthbook/useFeatureValue.ts
T
2024-01-11 12:31:14 +04:00

15 lines
557 B
TypeScript

import type { WidenPrimitives } from '@growthbook/growthbook';
import { useFeatureValue, useGrowthBook } from '@growthbook/growthbook-react';
import type { GrowthBookFeatures } from './init';
export default function useGbFeatureValue<Name extends keyof GrowthBookFeatures>(
name: Name,
fallback: GrowthBookFeatures[Name],
): { value: WidenPrimitives<GrowthBookFeatures[Name]>; isLoading: boolean } {
const value = useFeatureValue(name, fallback);
const growthBook = useGrowthBook();
return { value, isLoading: !(growthBook?.ready ?? true) };
}