Skip to content

Commit

Permalink
fix(@cubejs-client/react): options dependency for useEffect: check if…
Browse files Browse the repository at this point in the history
… `subscribe` has been changed in `useCubeQuery` (#632)

Co-authored-by: Vasilev <aleksandr.vasiliev@elinvar.de>
  • Loading branch information
vasilev-alex and Vasilev authored May 5, 2020
1 parent 0e99a0d commit 13ab5de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cubejs-client-react/src/useCubeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import { equals } from 'ramda';
import CubeContext from './CubeContext';
import isQueryPresent from './isQueryPresent';
import useDeepCompareMemoize from './useDeepCompareMemoize';

export default (query, options = {}) => {
const [mutexObj] = useState({});
Expand Down Expand Up @@ -65,7 +66,7 @@ export default (query, options = {}) => {
subscribeRequest = null;
}
};
}, [JSON.stringify(query), options.cubejsApi, context]);
}, useDeepCompareMemoize([query, options, context]));

return { isLoading, resultSet, error };
};
12 changes: 12 additions & 0 deletions packages/cubejs-client-react/src/useDeepCompareMemoize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useRef } from 'react';
import { equals } from 'ramda';

export default function useDeepCompareMemoize(value) {
const ref = useRef([]);

if (!equals(value, ref.current)) {
ref.current = value;
}

return ref.current;
}

0 comments on commit 13ab5de

Please sign in to comment.