File tree Expand file tree Collapse file tree 3 files changed +27
-59
lines changed
packages/cubejs-client-react/src/hooks Expand file tree Collapse file tree 3 files changed +27
-59
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,8 @@ import { isQueryPresent } from '@cubejs-client/core';
33
44import CubeContext from '../CubeContext' ;
55import useDeepCompareMemoize from './deep-compare-memoize' ;
6- import { useIsMounted } from './is-mounted' ;
76
87export function useCubeFetch ( method , options = { } ) {
9- const isMounted = useIsMounted ( ) ;
108 const context = useContext ( CubeContext ) ;
119 const mutexRef = useRef ( { } ) ;
1210
@@ -22,7 +20,8 @@ export function useCubeFetch(method, options = {}) {
2220 const cubeApi = options . cubeApi || context ?. cubeApi ;
2321 const query = loadOptions . query || options . query ;
2422
25- const queryCondition = method === 'meta' ? true : query && isQueryPresent ( query ) ;
23+ const queryCondition =
24+ method === 'meta' ? true : query && isQueryPresent ( query ) ;
2625
2726 if ( cubeApi && ( ignoreSkip || ! skip ) && queryCondition ) {
2827 setError ( null ) ;
@@ -40,20 +39,16 @@ export function useCubeFetch(method, options = {}) {
4039 try {
4140 const response = await cubeApi [ method ] ( ...args ) ;
4241
43- if ( isMounted ( ) ) {
44- setResponse ( {
45- response,
46- isLoading : false ,
47- } ) ;
48- }
42+ setResponse ( {
43+ response,
44+ isLoading : false ,
45+ } ) ;
4946 } catch ( error ) {
50- if ( isMounted ( ) ) {
51- setError ( error ) ;
52- setResponse ( {
53- isLoading : false ,
54- response : null ,
55- } ) ;
56- }
47+ setError ( error ) ;
48+ setResponse ( {
49+ isLoading : false ,
50+ response : null ,
51+ } ) ;
5752 }
5853 }
5954 }
Original file line number Diff line number Diff line change @@ -3,11 +3,9 @@ import { isQueryPresent, areQueriesEqual } from '@cubejs-client/core';
33
44import CubeContext from '../CubeContext' ;
55import useDeepCompareMemoize from './deep-compare-memoize' ;
6- import { useIsMounted } from './is-mounted' ;
76
87export function useCubeQuery ( query , options = { } ) {
98 const mutexRef = useRef ( { } ) ;
10- const isMounted = useIsMounted ( ) ;
119 const [ currentQuery , setCurrentQuery ] = useState ( null ) ;
1210 const [ isLoading , setLoading ] = useState ( ! options . skip ) ;
1311 const [ resultSet , setResultSet ] = useState ( null ) ;
@@ -42,21 +40,15 @@ export function useCubeQuery(query, options = {}) {
4240 castNumerics : Boolean ( typeof options . castNumerics === 'boolean' ? options . castNumerics : context ?. options ?. castNumerics )
4341 } ) ;
4442
45- if ( isMounted ( ) ) {
46- setResultSet ( response ) ;
47- setProgress ( null ) ;
48- }
43+ setResultSet ( response ) ;
44+ setProgress ( null ) ;
4945 } catch ( error ) {
50- if ( isMounted ( ) ) {
51- setError ( error ) ;
52- setResultSet ( null ) ;
53- setProgress ( null ) ;
54- }
46+ setError ( error ) ;
47+ setResultSet ( null ) ;
48+ setProgress ( null ) ;
5549 }
5650
57- if ( isMounted ( ) ) {
58- setLoading ( false ) ;
59- }
51+ setLoading ( false ) ;
6052 }
6153
6254 useEffect ( ( ) => {
@@ -95,27 +87,23 @@ export function useCubeQuery(query, options = {}) {
9587 progressCallback,
9688 } ,
9789 ( e , result ) => {
98- if ( isMounted ( ) ) {
99- if ( e ) {
100- setError ( e ) ;
101- } else {
102- setResultSet ( result ) ;
103- }
104- setLoading ( false ) ;
105- setProgress ( null ) ;
90+ if ( e ) {
91+ setError ( e ) ;
92+ } else {
93+ setResultSet ( result ) ;
10694 }
95+ setLoading ( false ) ;
96+ setProgress ( null ) ;
10797 }
10898 ) ;
10999 } else {
110100 await fetch ( ) ;
111101 }
112102 } catch ( e ) {
113- if ( isMounted ( ) ) {
114- setError ( e ) ;
115- setResultSet ( null ) ;
116- setLoading ( false ) ;
117- setProgress ( null ) ;
118- }
103+ setError ( e ) ;
104+ setResultSet ( null ) ;
105+ setLoading ( false ) ;
106+ setProgress ( null ) ;
119107 }
120108 }
121109 }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments