Replies: 2 comments 6 replies
-
Quickly quoting Tanner on this:
|
Beta Was this translation helpful? Give feedback.
6 replies
-
In case you wonder how to correctly type this HOC using typescript: import { useQuery, QueryKey, QueryFunction, UseQueryOptions, UseQueryResult } from 'react-query';
type Props<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
> = {
queryKey: TQueryKey;
queryFn: QueryFunction<TQueryFnData, TQueryKey>;
options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'queryFn'>;
children: (params: UseQueryResult<TData, TError>) => JSX.Element;
};
/**
* Utility component for using React-Query in class components
*/
export const UseQuery = <
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
props: Props<TQueryFnData, TError, TData, TQueryKey>
) => {
const query = useQuery(props.queryKey, props.queryFn, props.options);
return props.children(query);
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, is React query available for class components ? I searched the documentation but didn't find anything.
Or if not, are there any plans to add support in future ? I know hooks are the recommended approach by the React team but still lots of existing code still uses class components.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions