File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
packages/react/src/provider Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -8,19 +8,21 @@ import { Context } from './context';
88 *
99 */
1010export function useContextMutator ( ) {
11- const { domain } = useContext ( Context ) || { } ;
11+ const { domain } = useContext ( Context ) || { } ;
12+ const previousContext = useRef ( null ) ;
1213
13- async function mutateContext ( updatedContext : EvaluationContext ) : Promise < void > {
14- if ( ! domain ) {
15- // Set the global context
16- OpenFeature . setContext ( updatedContext ) ;
17- return ;
18- }
14+ const mutateContext = useCallback ( async ( updatedContext : EvaluationContext ) => {
15+ if ( previousContext . current !== updatedContext ) {
16+ if ( ! domain ) {
17+ OpenFeature . setContext ( updatedContext ) ;
18+ } else {
19+ OpenFeature . setContext ( domain , updatedContext ) ;
20+ }
21+ previousContext . current = updatedContext ;
22+ }
23+ } , [ domain ] ) ;
1924
20- OpenFeature . setContext ( domain , updatedContext ) ;
21- }
22-
23- return {
24- mutateContext,
25- } ;
25+ return {
26+ mutateContext,
27+ } ;
2628}
You can’t perform that action at this time.
0 commit comments