Commit f5ccadf0 authored by tom's avatar tom

better typing

parent 2c18ad2f
......@@ -3,6 +3,10 @@ import { GrowthBook } from '@growthbook/growthbook-react';
import config from 'configs/app';
import * as mixpanel from 'lib/mixpanel';
export interface GrowthBookFeatures {
test_value: string;
}
export const growthBook = (() => {
const feature = config.features.growthBook;
......@@ -10,7 +14,7 @@ export const growthBook = (() => {
return;
}
return new GrowthBook({
return new GrowthBook<GrowthBookFeatures>({
apiHost: 'https://cdn.growthbook.io',
clientKey: feature.clientKey,
enableDevMode: config.app.isDev,
......
import type { WidenPrimitives } from '@growthbook/growthbook';
import { useFeatureValue, useGrowthBook } from '@growthbook/growthbook-react';
export default function useGbFeatureValue<T extends Parameters<typeof useFeatureValue>[1]>(
name: Parameters<typeof useFeatureValue>[0],
fallback: T,
): { value: ReturnType<typeof useFeatureValue<T>>; isLoading: boolean } {
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();
......
......@@ -30,7 +30,7 @@ export default function useMixpanelInit() {
loaded: function() {
growthBook?.setAttributes({
...growthBook.getAttributes(),
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
language: window.navigator.language,
});
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment