Skip to content

Instantly share code, notes, and snippets.

@lukaszfiszer
Created November 9, 2019 13:18
Show Gist options
  • Save lukaszfiszer/0c1accfe49ede30f21ce99cfa6d51dcb to your computer and use it in GitHub Desktop.
Save lukaszfiszer/0c1accfe49ede30f21ce99cfa6d51dcb to your computer and use it in GitHub Desktop.
Typings for react-query package
declare module 'react-query' {
export type QueryKey = string | Array<string, object>;
export type QueryKeyFunction = () => QueryKey;
export type QueryFunction<TReturn> = (...args: any[]) => Promise<TReturn>;
export type QueryOptions = {
manual: boolean
pagination: boolean
getCanFetchMore: (lastPage: number, allPages: number) => boolean
staleTime: number;
retry: boolean | number;
retryDelay: number;
suspense: number
refetchInterval: number | false
onError: (err) => void;
}
export type QueryResult<TReturn> = {
data: null | TReturn;
error: null | Error;
isFetching: boolean;
isCached: boolean;
failureCount: number
isLoading: boolean
refetch: Function
}
export function useQuery<TReturn>(queryKey: QueryKey | QueryKeyFunction, queryFn: QueryFunction<TReturn>, options?: Partial<QueryOptions>): QueryResult<TReturn>;
export type MutationFunction<TReturn> = (...args) => Promise<TReturn>;
export type MutationResult<TReturn> = {
data: TReturn;
isLoading: boolean;
error: null | Error
}
export function useMutation<TReturn>(mutationFn: MutationFunction<TReturn>): [MutationFunction<TReturn>, MutationResult<TReturn>];
}
@lukaszfiszer
Copy link
Author

@bt4R9 you can use updated version from this PR: DefinitelyTyped/DefinitelyTyped#40312

@bt4R9
Copy link

bt4R9 commented Nov 13, 2019

@lukaszfiszer thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment