diff --git a/.vscode/settings.json b/.vscode/settings.json index 02db64b75..8c167a488 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,5 @@ { - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" - }, + "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true } diff --git a/src/hooks/useGrowthbookGetFeatureValue/index.tsx b/src/hooks/useGrowthbookGetFeatureValue/index.tsx index 5c55314b5..f9e311c5f 100644 --- a/src/hooks/useGrowthbookGetFeatureValue/index.tsx +++ b/src/hooks/useGrowthbookGetFeatureValue/index.tsx @@ -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 | boolean | string | []; interface UseGrowthbookGetFeatureValueArgs { - defaultValue?: featureValueTypes; - featureFlag: string; + defaultValue?: featureValueTypes; + featureFlag: string; } const useGrowthbookGetFeatureValue = ({ - defaultValue, - featureFlag, + defaultValue, + featureFlag, }: UseGrowthbookGetFeatureValueArgs): [T, boolean] => { - const resolvedDefaultValue: featureValueTypes = defaultValue !== undefined ? defaultValue : false; - const [featureFlagValue, setFeatureFlagValue] = useState( - (Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue) ?? resolvedDefaultValue) as T, - ); - const isGBLoaded = useIsGrowthbookIsLoaded(); + const resolvedDefaultValue: featureValueTypes = defaultValue !== undefined ? defaultValue : false; + const [featureFlagValue, setFeatureFlagValue] = useState( + (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; \ No newline at end of file