@cubejs-client/react 0.30.4 → 0.30.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubejs-client/react",
3
- "version": "0.30.4",
3
+ "version": "0.30.40",
4
4
  "author": "Cube Dev, Inc.",
5
5
  "license": "MIT",
6
6
  "engines": {},
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.1.2",
27
- "@cubejs-client/core": "^0.30.4",
27
+ "@cubejs-client/core": "^0.30.29",
28
28
  "anser": "^2.0.1",
29
29
  "core-js": "^3.6.5",
30
30
  "html-entities": "^2.3.2",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "react": ">=16.10.2"
46
46
  },
47
- "gitHead": "b7df8f6a3cfe104e639e0f7607868afa193ed0a3"
47
+ "gitHead": "001a804bafb808cb7bd027c81387998e7c8a45e4"
48
48
  }
@@ -3,10 +3,11 @@ import { isQueryPresent, areQueriesEqual } from '@cubejs-client/core';
3
3
 
4
4
  import CubeContext from '../CubeContext';
5
5
  import useDeepCompareMemoize from './deep-compare-memoize';
6
+ import { useIsMounted } from './is-mounted';
6
7
 
7
8
  export function useCubeQuery(query, options = {}) {
8
9
  const mutexRef = useRef({});
9
- const isMounted = useRef(true);
10
+ const isMounted = useIsMounted();
10
11
  const [currentQuery, setCurrentQuery] = useState(null);
11
12
  const [isLoading, setLoading] = useState(false);
12
13
  const [resultSet, setResultSet] = useState(null);
@@ -40,29 +41,23 @@ export function useCubeQuery(query, options = {}) {
40
41
  progressCallback,
41
42
  });
42
43
 
43
- if (isMounted.current) {
44
+ if (isMounted()) {
44
45
  setResultSet(response);
45
46
  setProgress(null);
46
47
  }
47
48
  } catch (error) {
48
- if (isMounted.current) {
49
+ if (isMounted()) {
49
50
  setError(error);
50
51
  setResultSet(null);
51
52
  setProgress(null);
52
53
  }
53
54
  }
54
55
 
55
- if (isMounted.current) {
56
+ if (isMounted()) {
56
57
  setLoading(false);
57
58
  }
58
59
  }
59
60
 
60
- useEffect(() => {
61
- return () => {
62
- isMounted.current = false;
63
- };
64
- }, []);
65
-
66
61
  useEffect(() => {
67
62
  const { skip = false, resetResultSetOnChange } = options;
68
63
 
@@ -99,7 +94,7 @@ export function useCubeQuery(query, options = {}) {
99
94
  progressCallback,
100
95
  },
101
96
  (e, result) => {
102
- if (isMounted.current) {
97
+ if (isMounted()) {
103
98
  if (e) {
104
99
  setError(e);
105
100
  } else {
@@ -114,7 +109,7 @@ export function useCubeQuery(query, options = {}) {
114
109
  await fetch();
115
110
  }
116
111
  } catch (e) {
117
- if (isMounted.current) {
112
+ if (isMounted()) {
118
113
  setError(e);
119
114
  setResultSet(null);
120
115
  setLoading(false);
@@ -1,9 +1,11 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
 
3
3
  export function useIsMounted() {
4
- const isMounted = useRef(true);
4
+ const isMounted = useRef(false);
5
5
 
6
6
  useEffect(() => {
7
+ isMounted.current = true;
8
+
7
9
  return () => {
8
10
  isMounted.current = false;
9
11
  };