Skip to content

Commit 6c179e3

Browse files
Copilothotlong
andcommitted
Changes before error encountered
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 90ad68d commit 6c179e3

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

packages/react/src/hooks/useExpression.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ export function useExpression(
2222
expression: string | boolean | number | null | undefined,
2323
context: Record<string, any> = {}
2424
): any {
25-
const evaluator = useMemo(
26-
() => new ExpressionEvaluator(context),
27-
[JSON.stringify(context)]
28-
);
29-
25+
// We evaluate directly without caching the evaluator to avoid issues with context changes
3026
return useMemo(
31-
() => evaluator.evaluate(expression),
32-
[evaluator, expression]
27+
() => {
28+
const evaluator = new ExpressionEvaluator(context);
29+
return evaluator.evaluate(expression);
30+
},
31+
[expression, context]
3332
);
3433
}
3534

@@ -46,13 +45,12 @@ export function useCondition(
4645
condition: string | boolean | undefined,
4746
context: Record<string, any> = {}
4847
): boolean {
49-
const evaluator = useMemo(
50-
() => new ExpressionEvaluator(context),
51-
[JSON.stringify(context)]
52-
);
53-
48+
// We evaluate directly without caching the evaluator to avoid issues with context changes
5449
return useMemo(
55-
() => evaluator.evaluateCondition(condition),
56-
[evaluator, condition]
50+
() => {
51+
const evaluator = new ExpressionEvaluator(context);
52+
return evaluator.evaluateCondition(condition);
53+
},
54+
[condition, context]
5755
);
5856
}

0 commit comments

Comments
 (0)