4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { useContext , useEffect } from "react" ;
7
+ import { useContext } from "react" ;
8
8
import { UserContext } from "../user-context" ;
9
9
import { getGitpodService } from "../service/service" ;
10
10
import { trackLocation } from "../Analytics" ;
@@ -19,7 +19,7 @@ export const useUserLoader = () => {
19
19
20
20
// For now, we're using the user context to store the user, but letting react-query handle the loading
21
21
// In the future, we should remove the user context and use react-query to access the user
22
- const userQuery = useQuery ( {
22
+ const { isLoading } = useQuery ( {
23
23
queryKey : noPersistence ( [ "current-user" ] ) ,
24
24
queryFn : async ( ) => {
25
25
const user = await getGitpodService ( ) . server . getLoggedInUser ( ) ;
@@ -40,18 +40,13 @@ export const useUserLoader = () => {
40
40
retryDelay : ( attemptIndex ) => Math . min ( 1000 * 2 ** attemptIndex , 10000 ) ,
41
41
cacheTime : 1000 * 60 * 60 * 1 , // 1 hour
42
42
staleTime : 1000 * 60 * 60 * 1 , // 1 hour
43
-
43
+ onSuccess : ( loadedUser ) => {
44
+ setUser ( loadedUser ) ;
45
+ } ,
44
46
onSettled : ( loadedUser ) => {
45
47
trackLocation ( ! ! loadedUser ) ;
46
48
} ,
47
49
} ) ;
48
50
49
- // onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
50
- useEffect ( ( ) => {
51
- if ( userQuery . data ) {
52
- setUser ( userQuery . data ) ;
53
- }
54
- } , [ userQuery . data , setUser ] ) ;
55
-
56
- return { user, loading : userQuery . isLoading } ;
51
+ return { user, loading : isLoading } ;
57
52
} ;
0 commit comments