Skip to content

Commit fa2a49a

Browse files
committed
chore: Upgrade react-query to v5
1 parent 7ab080d commit fa2a49a

File tree

12 files changed

+56
-75
lines changed

12 files changed

+56
-75
lines changed

.github/workflows/e2e_android.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: E2E Android
22
on:
3-
push:
4-
branches:
5-
- master
63
workflow_call:
74

85
jobs:

.github/workflows/e2e_ios.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: E2E iOS
22
on:
3-
push:
4-
branches:
5-
- master
63
workflow_call:
74

85
jobs:

Gemfile.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ GEM
109109
xcodeproj (>= 1.13.0, < 2.0.0)
110110
xcpretty (~> 0.3.0)
111111
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
112-
fastlane-plugin-firebase_app_distribution (0.9.0)
112+
fastlane-plugin-firebase_app_distribution (0.9.1)
113113
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
114114
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
115115
fastlane-plugin-increment_version_code (0.4.3)
@@ -165,7 +165,7 @@ GEM
165165
mini_magick (4.12.0)
166166
mini_mime (1.1.5)
167167
multi_json (1.15.0)
168-
multipart-post (2.4.0)
168+
multipart-post (2.4.1)
169169
nanaimo (0.3.0)
170170
naturally (2.2.1)
171171
nkf (0.2.0)
@@ -179,7 +179,8 @@ GEM
179179
trailblazer-option (>= 0.1.1, < 0.2.0)
180180
uber (< 0.2.0)
181181
retriable (3.1.2)
182-
rexml (3.2.6)
182+
rexml (3.2.8)
183+
strscan (>= 3.0.9)
183184
rouge (2.0.7)
184185
ruby2_keywords (0.0.5)
185186
rubyzip (2.3.2)
@@ -192,6 +193,7 @@ GEM
192193
simctl (1.6.10)
193194
CFPropertyList
194195
naturally
196+
strscan (3.1.0)
195197
terminal-notifier (2.0.0)
196198
terminal-table (3.0.2)
197199
unicode-display_width (>= 1.1.1, < 3)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@react-navigation/drawer": "^6.6.15",
2828
"@react-navigation/native": "^6.1.17",
2929
"@react-navigation/stack": "^6.3.29",
30-
"@tanstack/react-query": "^4.36.1",
30+
"@tanstack/react-query": "^5.36.2",
3131
"axios": "^1.6.8",
3232
"fast-text-encoding": "^1.0.6",
3333
"nativewind": "^4.0.36",

src/context/auth/authContextController/AuthContextController.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const AuthContextController = ({ children }: AuthContextControllerProps)
2424
},
2525
);
2626

27-
const { mutateAsync: login, isLoading: isAuthenticating } = useMutation('loginMutation', {
27+
const { mutateAsync: login, isPending: isAuthenticating } = useMutation('loginMutation', {
2828
onSuccess: (res) => {
2929
dispatch(
3030
setTokens({
@@ -45,21 +45,25 @@ export const AuthContextController = ({ children }: AuthContextControllerProps)
4545
isLoadingAndEnabled,
4646
isSuccess: isUserSuccess,
4747
remove: resetUser,
48+
isError: isUserError,
4849
} = useUser({
4950
enabled: !!state.accessToken,
50-
onError: () => {
51-
dispatch(resetTokens());
52-
},
5351
});
5452

53+
useEffect(() => {
54+
if (isUserError) {
55+
dispatch(resetTokens());
56+
}
57+
}, [isUserError]);
58+
5559
const logout = useCallback(() => {
5660
resetUser();
5761
dispatch(resetTokens());
5862
}, [resetUser]);
5963

6064
useEffect(() => {
6165
setAuthStorage(state);
62-
}, [state]);
66+
}, [state, setAuthStorage]);
6367

6468
const value: AuthContextValue = useMemo(
6569
() => ({
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
3-
import {
4-
QueryKey,
5-
useInfiniteQuery as useRQInfiniteQuery,
6-
UseInfiniteQueryOptions,
7-
UseInfiniteQueryResult,
8-
} from '@tanstack/react-query';
1+
import { QueryKey, useInfiniteQuery as useRQInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
92

103
import { AxiosInfiniteQueriesType, queries } from 'api/actions';
114
import { DataForQuery, GetQueryParams } from 'api/types/types';
@@ -20,15 +13,16 @@ import { useApiClient } from 'hooks/useApiClient/useApiClient';
2013
export const useInfiniteQuery = <Key extends keyof AxiosInfiniteQueriesType, TError = unknown>(
2114
query: Key,
2215
args?: GetQueryParams<Key>,
23-
options?: UseInfiniteQueryOptions<DataForQuery<Key>, TError>,
16+
options?: Omit<UseInfiniteQueryOptions<DataForQuery<Key>, TError>, 'queryKey' | 'queryFn'>,
2417
) => {
2518
const { client } = useApiClient();
2619
const queryFn = queries[query](client);
2720
const queryKey: QueryKey = [query];
2821

29-
return useRQInfiniteQuery(
22+
return useRQInfiniteQuery<DataForQuery<Key>, TError>({
3023
queryKey,
31-
async ({ pageParam }: { pageParam?: string }) => await queryFn({ pageParam, ...(args || {}) }),
32-
options as any,
33-
) as UseInfiniteQueryResult<DataForQuery<Key>, TError>;
24+
queryFn: async ({ pageParam }: { pageParam?: string }) => await queryFn({ pageParam, ...(args || {}) }),
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26+
...(options as any),
27+
});
3428
};

src/hooks/useMutation/useMutation.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
UseMutationResult,
3-
useMutation as useRQMutation,
4-
UseMutationOptions,
5-
MutationKey,
6-
} from '@tanstack/react-query';
1+
import { useMutation as useRQMutation, UseMutationOptions, MutationKey } from '@tanstack/react-query';
72

83
import { AxiosMutationsType, mutations } from 'api/actions';
94
import { useApiClient } from 'hooks/useApiClient/useApiClient';
@@ -25,10 +20,10 @@ export const useMutation = <Key extends keyof AxiosMutationsType, TError = unkno
2520
const mutationFn = mutations[mutation](client);
2621
const mutationKey: MutationKey = [mutation];
2722

28-
return useRQMutation(
23+
return useRQMutation<DataForMutation<Key>, TError, GetMutationParams<Key>>({
2924
mutationKey,
30-
async (args) => await mutationFn(args),
25+
mutationFn: async (args) => await mutationFn(args),
3126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32-
options as any,
33-
) as UseMutationResult<DataForMutation<Key>, TError, GetMutationParams<Key>>;
27+
...(options as any),
28+
});
3429
};

src/hooks/useQuery/useQuery.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('useQuery', () => {
6767
),
6868
});
6969

70-
expect(result.current.status).toBe('loading');
70+
expect(result.current.status).toBe('pending');
7171
await waitFor(() => {
7272
expect(result.current.status).toBe('error');
7373
});

src/hooks/useQuery/useQuery.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { QueryKey, UseQueryResult, UseQueryOptions, useQuery as useRQQuery } from '@tanstack/react-query';
1+
import { QueryKey, UseQueryOptions, useQuery as useRQQuery, useQueryClient } from '@tanstack/react-query';
2+
import { useCallback } from 'react';
23

34
import { AxiosQueriesType, queries } from 'api/actions';
45
import { DataForQuery, GetQueryParams } from 'api/types/types';
@@ -8,18 +9,25 @@ import { parseQueryKey } from 'utils/parseQueryKey';
89
export const useQuery = <Key extends keyof AxiosQueriesType, TError = unknown>(
910
query: Key,
1011
args: GetQueryParams<Key>,
11-
options?: UseQueryOptions<DataForQuery<Key>, TError>,
12+
options?: Omit<UseQueryOptions<DataForQuery<Key>, TError>, 'queryKey' | 'queryFn'>,
1213
) => {
1314
const { client } = useApiClient();
15+
const queryClient = useQueryClient();
1416
const queryFn = queries[query](client);
1517
const queryKey: QueryKey = parseQueryKey(query, args);
1618

17-
const result = useRQQuery(
19+
const result = useRQQuery<DataForQuery<Key>, TError>({
1820
queryKey,
19-
async () => await queryFn(args),
21+
queryFn: async () => await queryFn(args),
2022
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21-
options as any,
22-
) as UseQueryResult<DataForQuery<Key>, TError>;
23+
...(options as any),
24+
});
2325

24-
return { ...result, isLoadingAndEnabled: result.isLoading && result.fetchStatus !== 'idle' };
26+
const remove = useCallback(() => queryClient.removeQueries({ queryKey }), [queryClient, queryKey]);
27+
28+
return {
29+
...result,
30+
isLoadingAndEnabled: result.isLoading && result.fetchStatus !== 'idle',
31+
remove,
32+
};
2533
};

src/hooks/useUser/useUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { GetMeQueryResponse } from 'api/actions/auth/auth.types';
44

55
import { useQuery } from '../useQuery/useQuery';
66

7-
export const useUser = (options?: UseQueryOptions<GetMeQueryResponse>) => {
7+
export const useUser = (options?: Omit<UseQueryOptions<GetMeQueryResponse>, 'queryKey' | 'queryFn'>) => {
88
return useQuery('getCurrentUser', {}, options);
99
};

0 commit comments

Comments
 (0)