File tree 9 files changed +47
-29
lines changed
9 files changed +47
-29
lines changed Original file line number Diff line number Diff line change 30
30
"react-error-boundary" : " ^3.1.3" ,
31
31
"react-helmet-async" : " ^1.1.2" ,
32
32
"react-hook-form" : " ^7.7.1" ,
33
- "react-query" : " ^3.18.1 " ,
33
+ "react-query" : " ^3.34.15 " ,
34
34
"react-query-auth" : " ^1.0.0" ,
35
35
"react-router-dom" : " ^6.0.0-beta.0" ,
36
36
"react-scripts" : " 4.0.3" ,
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { Comment } from '../types' ;
7
7
@@ -13,15 +13,17 @@ export const getComments = ({ discussionId }: { discussionId: string }): Promise
13
13
} ) ;
14
14
} ;
15
15
16
+ type QueryFnType = typeof getComments ;
17
+
16
18
type UseCommentsOptions = {
17
19
discussionId : string ;
18
- config ?: QueryConfig < typeof getComments > ;
20
+ config ?: QueryConfig < QueryFnType > ;
19
21
} ;
20
22
21
23
export const useComments = ( { discussionId, config } : UseCommentsOptions ) => {
22
- return useQuery ( {
23
- ...config ,
24
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
24
25
queryKey : [ 'comments' , discussionId ] ,
25
26
queryFn : ( ) => getComments ( { discussionId } ) ,
27
+ ...config ,
26
28
} ) ;
27
29
} ;
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { Discussion } from '../types' ;
7
7
8
8
export const getDiscussion = ( { discussionId } : { discussionId : string } ) : Promise < Discussion > => {
9
9
return axios . get ( `/discussions/${ discussionId } ` ) ;
10
10
} ;
11
+
12
+ type QueryFnType = typeof getDiscussion ;
13
+
11
14
type UseDiscussionOptions = {
12
15
discussionId : string ;
13
- config ?: QueryConfig < typeof getDiscussion > ;
16
+ config ?: QueryConfig < QueryFnType > ;
14
17
} ;
15
18
16
19
export const useDiscussion = ( { discussionId, config } : UseDiscussionOptions ) => {
17
- return useQuery ( {
20
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
18
21
...config ,
19
22
queryKey : [ 'discussion' , discussionId ] ,
20
23
queryFn : ( ) => getDiscussion ( { discussionId } ) ,
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { Discussion } from '../types' ;
7
7
8
8
export const getDiscussions = ( ) : Promise < Discussion [ ] > => {
9
9
return axios . get ( '/discussions' ) ;
10
10
} ;
11
11
12
+ type QueryFnType = typeof getDiscussions ;
13
+
12
14
type UseDiscussionsOptions = {
13
- config ?: QueryConfig < typeof getDiscussions > ;
15
+ config ?: QueryConfig < QueryFnType > ;
14
16
} ;
15
17
16
18
export const useDiscussions = ( { config } : UseDiscussionsOptions = { } ) => {
17
- return useQuery ( {
19
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
18
20
...config ,
19
21
queryKey : [ 'discussions' ] ,
20
22
queryFn : ( ) => getDiscussions ( ) ,
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { Team } from '../types' ;
7
7
8
8
export const getMyTeam = ( ) : Promise < Team > => {
9
9
return axios . get ( '/team' ) ;
10
10
} ;
11
11
12
+ type QueryFnType = typeof getMyTeam ;
13
+
12
14
type UseMyTeamOptions = {
13
- config ?: QueryConfig < typeof getMyTeam > ;
15
+ config ?: QueryConfig < QueryFnType > ;
14
16
} ;
15
17
16
18
export const useMyTeam = ( { config } : UseMyTeamOptions = { } ) => {
17
- return useQuery ( {
19
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
18
20
...config ,
19
21
queryKey : [ 'my-teams' ] ,
20
22
queryFn : ( ) => getMyTeam ( ) ,
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { Team } from '../types' ;
7
7
8
8
export const getTeams = ( ) : Promise < Team [ ] > => {
9
9
return axios . get ( '/teams' ) ;
10
10
} ;
11
11
12
+ type QueryFnType = typeof getTeams ;
13
+
12
14
type UseTeamsOptions = {
13
- config ?: QueryConfig < typeof getTeams > ;
15
+ config ?: QueryConfig < QueryFnType > ;
14
16
} ;
15
17
16
18
export const useTeams = ( { config = { } } : UseTeamsOptions = { } ) => {
17
- return useQuery ( {
19
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
18
20
...config ,
19
21
queryKey : [ 'teams' ] ,
20
22
queryFn : ( ) => getTeams ( ) ,
Original file line number Diff line number Diff line change 1
1
import { useQuery } from 'react-query' ;
2
2
3
3
import { axios } from '@/lib/axios' ;
4
- import { QueryConfig } from '@/lib/react-query' ;
4
+ import { ExtractFnReturnType , QueryConfig } from '@/lib/react-query' ;
5
5
6
6
import { User } from '../types' ;
7
7
8
8
export const getUsers = ( ) : Promise < User [ ] > => {
9
9
return axios . get ( `/users` ) ;
10
10
} ;
11
11
12
+ type QueryFnType = typeof getUsers ;
13
+
12
14
type UseUsersOptions = {
13
- config ?: QueryConfig < typeof getUsers > ;
15
+ config ?: QueryConfig < QueryFnType > ;
14
16
} ;
15
17
16
18
export const useUsers = ( { config } : UseUsersOptions = { } ) => {
17
- return useQuery ( {
19
+ return useQuery < ExtractFnReturnType < QueryFnType > > ( {
18
20
...config ,
19
21
queryKey : [ 'users' ] ,
20
22
queryFn : ( ) => getUsers ( ) ,
Original file line number Diff line number Diff line change @@ -12,12 +12,17 @@ const queryConfig: DefaultOptions = {
12
12
13
13
export const queryClient = new QueryClient ( { defaultOptions : queryConfig } ) ;
14
14
15
- export type QueryConfig < FetcherFnType extends ( ...args : any ) => any > = UseQueryOptions <
16
- PromiseValue < ReturnType < FetcherFnType > >
15
+ export type ExtractFnReturnType < FnType extends ( ...args : any ) => any > = PromiseValue <
16
+ ReturnType < FnType >
17
17
> ;
18
18
19
- export type MutationConfig < FetcherFnType extends ( ...args : any ) => any > = UseMutationOptions <
20
- PromiseValue < ReturnType < FetcherFnType > > ,
19
+ export type QueryConfig < QueryFnType extends ( ...args : any ) => any > = Omit <
20
+ UseQueryOptions < ExtractFnReturnType < QueryFnType > > ,
21
+ 'queryKey' | 'queryFn'
22
+ > ;
23
+
24
+ export type MutationConfig < MutationFnType extends ( ...args : any ) => any > = UseMutationOptions <
25
+ ExtractFnReturnType < MutationFnType > ,
21
26
AxiosError ,
22
- Parameters < FetcherFnType > [ 0 ]
27
+ Parameters < MutationFnType > [ 0 ]
23
28
> ;
Original file line number Diff line number Diff line change @@ -13760,10 +13760,10 @@ react-query-auth@^1.0.0:
13760
13760
resolved "https://registry.yarnpkg.com/react-query-auth/-/react-query-auth-1.0.0.tgz#d8bd5fbf88d24c2c86cc406c1ddb6c854372ce8c"
13761
13761
integrity sha512-SnxqQzCg0C4CUAWGddqaSTvi2PPbYH1yAT8kC8+b6vYY58lKmsTcVxvcpDIW91BSOgzP6aILUJlvORGRdgsEbg==
13762
13762
13763
- react-query@^3.18.1 :
13764
- version "3.18.1 "
13765
- resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.18.1 .tgz#893b5475a7b4add099e007105317446f7a2cd310 "
13766
- integrity sha512-17lv3pQxU9n+cB5acUv0/cxNTjo9q8G+RsedC6Ax4V9D8xEM7Q5xf9xAbCPdEhDrrnzPjTls9fQEABKRSi7OJA ==
13763
+ react-query@^3.34.15 :
13764
+ version "3.34.15 "
13765
+ resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.34.15 .tgz#9e143b7d0aa39c515102a35120d5518ad91b10f6 "
13766
+ integrity sha512-dOhGLB5RT3p+wWj0rVdAompSg+R9t6oMRk+JhU8DP0tpJM2UyIv3r4Kk0zUkHSxT+QG34hFdrgdqxVWxgeNq4g ==
13767
13767
dependencies:
13768
13768
"@babel/runtime" "^7.5.5"
13769
13769
broadcast-channel "^3.4.1"
You can’t perform that action at this time.
0 commit comments