Skip to content

Commit

Permalink
chore: reverted prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienne-deriv committed Oct 2, 2024
1 parent a4f074f commit d3ab08d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
54 changes: 27 additions & 27 deletions src/hooks/useGrowthbookGetFeatureValue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { useEffect, useState } from 'react';
import { Analytics } from '@deriv-com/analytics';
import useIsGrowthbookIsLoaded from '../useIsGrowthbookLoaded';
import useIsGrowthbookIsLoaded from './useIsGrowthbookLoaded';

type featureValueTypes = Record<string, boolean> | boolean | string | [];

interface UseGrowthbookGetFeatureValueArgs {
defaultValue?: featureValueTypes;
featureFlag: string;
defaultValue?: featureValueTypes;
featureFlag: string;
}

const useGrowthbookGetFeatureValue = <T,>({
defaultValue,
featureFlag,
defaultValue,
featureFlag,
}: UseGrowthbookGetFeatureValueArgs): [T, boolean] => {
const resolvedDefaultValue: featureValueTypes = defaultValue !== undefined ? defaultValue : false;
const [featureFlagValue, setFeatureFlagValue] = useState<T>(
(Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue) ?? resolvedDefaultValue) as T,
);
const isGBLoaded = useIsGrowthbookIsLoaded();
const resolvedDefaultValue: featureValueTypes = defaultValue !== undefined ? defaultValue : false;
const [featureFlagValue, setFeatureFlagValue] = useState<T>(
(Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue) ?? resolvedDefaultValue) as T
);
const isGBLoaded = useIsGrowthbookIsLoaded();

useEffect(() => {
if (isGBLoaded) {
if (Analytics?.getInstances()?.ab) {
const setFeatureValue = () => {
const value = Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue) as T;
setFeatureFlagValue(value);
};
setFeatureValue();
Analytics?.getInstances()?.ab?.GrowthBook?.setRenderer(() => {
// this will be called whenever the feature flag value changes and acts as a event listener
setFeatureValue();
});
}
}
}, [isGBLoaded, resolvedDefaultValue, featureFlag]);
useEffect(() => {
if (isGBLoaded) {
if (Analytics?.getInstances()?.ab) {
const setFeatureValue = () => {
const value = Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue) as T;
setFeatureFlagValue(value);
};
setFeatureValue();
Analytics?.getInstances()?.ab?.GrowthBook?.setRenderer(() => {
// this will be called whenever the feature flag value changes and acts as a event listener
setFeatureValue();
});
}
}
}, [isGBLoaded, resolvedDefaultValue, featureFlag]);

return [featureFlagValue as T, isGBLoaded];
return [featureFlagValue as T, isGBLoaded];
};

export default useGrowthbookGetFeatureValue;
export default useGrowthbookGetFeatureValue;

0 comments on commit d3ab08d

Please sign in to comment.