44 * See License.AGPL.txt in the project root for license information.
55 */
66
7- import { useContext , useEffect } from "react" ;
7+ import { useContext } from "react" ;
88import { UserContext } from "../user-context" ;
99import { getGitpodService } from "../service/service" ;
1010import { trackLocation } from "../Analytics" ;
@@ -19,7 +19,7 @@ export const useUserLoader = () => {
1919
2020 // For now, we're using the user context to store the user, but letting react-query handle the loading
2121 // 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 ( {
2323 queryKey : noPersistence ( [ "current-user" ] ) ,
2424 queryFn : async ( ) => {
2525 const user = await getGitpodService ( ) . server . getLoggedInUser ( ) ;
@@ -40,18 +40,13 @@ export const useUserLoader = () => {
4040 retryDelay : ( attemptIndex ) => Math . min ( 1000 * 2 ** attemptIndex , 10000 ) ,
4141 cacheTime : 1000 * 60 * 60 * 1 , // 1 hour
4242 staleTime : 1000 * 60 * 60 * 1 , // 1 hour
43-
43+ onSuccess : ( loadedUser ) => {
44+ setUser ( loadedUser ) ;
45+ } ,
4446 onSettled : ( loadedUser ) => {
4547 trackLocation ( ! ! loadedUser ) ;
4648 } ,
4749 } ) ;
4850
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 } ;
5752} ;
0 commit comments