mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-02 01:17:58 +02:00
fix: now feature is not pulled from server if not defined (#10000)
This commit is contained in:
parent
45c2a0b939
commit
0255cf137a
@ -1,9 +1,10 @@
|
|||||||
import useSWR, { type SWRConfiguration } from 'swr';
|
import type { SWRConfiguration } from 'swr';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { emptyFeature } from './emptyFeature.js';
|
import { emptyFeature } from './emptyFeature.ts';
|
||||||
import handleErrorResponses from '../httpErrorResponseHandler.js';
|
import handleErrorResponses from '../httpErrorResponseHandler.ts';
|
||||||
import { formatApiPath } from 'utils/formatPath';
|
import { formatApiPath } from 'utils/formatPath';
|
||||||
import type { IFeatureToggle } from 'interfaces/featureToggle';
|
import type { IFeatureToggle } from 'interfaces/featureToggle';
|
||||||
|
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR.ts';
|
||||||
|
|
||||||
export interface IUseFeatureOutput {
|
export interface IUseFeatureOutput {
|
||||||
feature: IFeatureToggle;
|
feature: IFeatureToggle;
|
||||||
@ -25,7 +26,9 @@ export const useFeature = (
|
|||||||
): IUseFeatureOutput => {
|
): IUseFeatureOutput => {
|
||||||
const path = formatFeatureApiPath(projectId, featureId);
|
const path = formatFeatureApiPath(projectId, featureId);
|
||||||
|
|
||||||
const { data, error, mutate } = useSWR<IFeatureResponse>(
|
const { data, error, mutate } = useConditionalSWR<IFeatureResponse>(
|
||||||
|
Boolean(featureId && projectId),
|
||||||
|
{ status: 404 },
|
||||||
['useFeature', path],
|
['useFeature', path],
|
||||||
() => featureFetcher(path),
|
() => featureFetcher(path),
|
||||||
options,
|
options,
|
||||||
|
Loading…
Reference in New Issue
Block a user