-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
useQuery as useTanstackQuery, | ||
type DefaultError, | ||
type QueryClient, | ||
type QueryKey, | ||
type UseQueryOptions, | ||
type UseQueryResult, | ||
} from '@tanstack/react-query' | ||
import type { ExactPartial } from 'viem' | ||
import { fallbackQueryClient } from '../query.js' | ||
import type { Compute } from '../utils/types.js' | ||
|
||
export type UseQueryParameters< | ||
QueryFnData = unknown, | ||
Error = DefaultError, | ||
Data = QueryFnData, | ||
TheQueryKey extends QueryKey = QueryKey, | ||
> = Compute< | ||
ExactPartial< | ||
Omit<UseQueryOptions<QueryFnData, Error, Data, TheQueryKey>, 'initialData'> | ||
> & { | ||
// Fix `initialData` type | ||
initialData?: | ||
| UseQueryOptions<QueryFnData, Error, Data, TheQueryKey>['initialData'] | ||
| undefined | ||
} | ||
> | ||
|
||
export type UseQueryReturnType< | ||
Data = unknown, | ||
Error = DefaultError, | ||
> = UseQueryResult<Data, Error> | ||
|
||
export const useQuery = <Parameters, Data, Error>( | ||
key: QueryKey, | ||
queryParameters: Exclude<Parameters, 'queryKey'>, | ||
queryClient?: QueryClient, | ||
): UseQueryReturnType<Data, Error> => { | ||
const parameters = { | ||
...queryParameters, | ||
queryKey: key, | ||
} | ||
|
||
// TODO: figure out why this is necessary | ||
// @ts-ignore | ||
return useTanstackQuery( | ||
{ ...parameters } as any, | ||
queryClient ?? fallbackQueryClient, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Compute<Type> = { [key in keyof Type]: Type[key] } & unknown |