Skip to content

Commit a85f71a

Browse files
[FSSDK-12293] improvements
1 parent 655d6f5 commit a85f71a

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/hooks/useDecide.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export interface UseDecideResult {
4545
export function useDecide(flagKey: string, config?: UseDecideConfig): UseDecideResult {
4646
const { store, client } = useOptimizelyContext();
4747
const decideOptions = useStableArray(config?.decideOptions);
48-
const defaultDecision = useMemo(() => createDefaultDecision(flagKey), [flagKey]);
49-
5048
// --- General state subscription ---
5149
// store.getState() returns a new object on every state change,
5250
// so Object.is comparison works naturally.
@@ -67,21 +65,19 @@ export function useDecide(flagKey: string, config?: UseDecideConfig): UseDecideR
6765

6866
// --- Derive decision ---
6967
return useMemo(() => {
68+
void fdVersion; // referenced to satisfy exhaustive-deps; triggers recomputation on forced decision changes
7069
const { userContext, error } = state;
7170
const hasConfig = client.getOptimizelyConfig() !== null;
7271

7372
if (error) {
74-
return { decision: defaultDecision, isLoading: false, error };
73+
return { decision: createDefaultDecision(flagKey), isLoading: false, error };
7574
}
7675

7776
if (!hasConfig || userContext === null) {
78-
return { decision: defaultDecision, isLoading: true, error: null };
77+
return { decision: createDefaultDecision(flagKey), isLoading: true, error: null };
7978
}
8079

8180
const decision = userContext.decide(flagKey, decideOptions);
8281
return { decision, isLoading: false, error: null };
83-
// fdVersion is not referenced in the callback but triggers recomputation
84-
// when a forced decision changes for this flagKey.
85-
// eslint-disable-next-line react-hooks/exhaustive-deps
86-
}, [state, fdVersion, client, flagKey, decideOptions, defaultDecision]);
82+
}, [fdVersion, state, client, flagKey, decideOptions]);
8783
}

0 commit comments

Comments
 (0)