|
1 |
| -import { useQuery, QueryKey } from '@tanstack/react-query' |
2 | 1 | import type { UseQueryOptions } from '@tanstack/react-query'
|
| 2 | +import { QueryKey, useQuery } from '@tanstack/react-query' |
| 3 | +import { queryClient } from '@/shared/api/query-client' |
3 | 4 |
|
4 |
| -export function createQueryHook<TParams, TData, TQueryKey extends QueryKey>( |
| 5 | +export const createQueryHook = <TParams, TData, TQueryKey extends QueryKey>( |
5 | 6 | getQueryOptions: (params: TParams, condition?: boolean) => UseQueryOptions<TData, Error, TData, TQueryKey>,
|
6 |
| -) { |
7 |
| - return (params: TParams, condition?: boolean) => { |
8 |
| - const options = getQueryOptions(params, condition) |
9 |
| - return useQuery<TData, Error, TData, TQueryKey>(options) |
10 |
| - } |
| 7 | +) => (params: TParams, condition?: boolean) => { |
| 8 | + const options = getQueryOptions(params, condition) |
| 9 | + return useQuery<TData, Error, TData, TQueryKey>(options) |
11 | 10 | }
|
| 11 | + |
| 12 | +export const createGetQueryData = <KeysObject extends Record<keyof KeysObject & string, (arg: any) => any>>( |
| 13 | + keys: KeysObject |
| 14 | +) => |
| 15 | + <Result, Key extends keyof KeysObject = keyof KeysObject>(key: Key, keyData: Parameters<KeysObject[Key]>[0]) => |
| 16 | + queryClient.getQueryData<Result>(keys[key](keyData)) |
0 commit comments