Skip to content

Commit 13ab5de

Browse files
vasilev-alexVasilev
andauthored
fix(@cubejs-client/react): options dependency for useEffect: check if subscribe has been changed in useCubeQuery (#632)
Co-authored-by: Vasilev <aleksandr.vasiliev@elinvar.de>
1 parent 0e99a0d commit 13ab5de

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/cubejs-client-react/src/useCubeQuery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
import { equals } from 'ramda';
55
import CubeContext from './CubeContext';
66
import isQueryPresent from './isQueryPresent';
7+
import useDeepCompareMemoize from './useDeepCompareMemoize';
78

89
export default (query, options = {}) => {
910
const [mutexObj] = useState({});
@@ -65,7 +66,7 @@ export default (query, options = {}) => {
6566
subscribeRequest = null;
6667
}
6768
};
68-
}, [JSON.stringify(query), options.cubejsApi, context]);
69+
}, useDeepCompareMemoize([query, options, context]));
6970

7071
return { isLoading, resultSet, error };
7172
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useRef } from 'react';
2+
import { equals } from 'ramda';
3+
4+
export default function useDeepCompareMemoize(value) {
5+
const ref = useRef([]);
6+
7+
if (!equals(value, ref.current)) {
8+
ref.current = value;
9+
}
10+
11+
return ref.current;
12+
}

0 commit comments

Comments
 (0)