mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: too many reqs to feature toggle endpoint (#2650)
Fixes an issue where the feature toggle endpoint gets request too many times repeatedly.
This commit is contained in:
		
							parent
							
								
									58622bbf99
								
							
						
					
					
						commit
						bc77342380
					
				@ -1,5 +1,5 @@
 | 
			
		||||
import useSWR, { SWRConfiguration } from 'swr';
 | 
			
		||||
import { useCallback, useEffect } from 'react';
 | 
			
		||||
import { useCallback } from 'react';
 | 
			
		||||
import { emptyFeature } from './emptyFeature';
 | 
			
		||||
import handleErrorResponses from '../httpErrorResponseHandler';
 | 
			
		||||
import { formatApiPath } from 'utils/formatPath';
 | 
			
		||||
@ -32,7 +32,7 @@ export const useFeature = (
 | 
			
		||||
    } = uiConfig;
 | 
			
		||||
 | 
			
		||||
    const { data, error, mutate } = useSWR<IFeatureResponse>(
 | 
			
		||||
        ['useFeature', path],
 | 
			
		||||
        ['useFeature', path, variantsPerEnvironment],
 | 
			
		||||
        () => featureFetcher(path, variantsPerEnvironment),
 | 
			
		||||
        options
 | 
			
		||||
    );
 | 
			
		||||
@ -41,10 +41,6 @@ export const useFeature = (
 | 
			
		||||
        mutate().catch(console.warn);
 | 
			
		||||
    }, [mutate]);
 | 
			
		||||
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
        mutate();
 | 
			
		||||
    }, [mutate, variantsPerEnvironment]);
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        feature: data?.body || emptyFeature,
 | 
			
		||||
        refetchFeature,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user