-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Describe the bug
Look at the types at https://github.com/refinedev/refine/blob/0842b702dad2c95966b2a2b49da0a66527bcbea3/packages/core/src/hooks/show/types.ts#L54C1-L58
queryOptions?: UseQueryOptions<
GetOneResponse<TQueryFnData>,
TError,
GetOneResponse<TData>
>;They should be:
queryOptions?: UseQueryOptions<
TQueryFnData,
TError,
TData
>;(This also applies elsewhere to useTable and other hooks with a queryOptions property)
The problem with the former is they are inconsistent with how ReactQuery defines query types.
For example, if I implement queryOptions.queryFn, It won't accept an API that returns type TQueryFnData, insisting that it's wrapped in a { data: TQueryFnData } container. However, in ReactQuery, you just return TQueryFnData from queryFn and ReactQuery itself owns the metadata/lifecycle container, wrapping the returned value in a QueryObserverBaseResult which contains a { data: TQueryFnData } property.
As a consequence, the result object is doubly wrapped: { data: { data: TQueryFnData }}!
I can work around this by wrapping the response in a redundant GetOneResponse, but this should not be necessary. It would be better if the double wrapping were removed.
Steps To Reproduce
Implement queryOptions.queryFn using options that work in a plain useQuery invocation
Expected behavior
Use of ReactQuery should be a thin wrapper that works along with existing knowledge of the ReactQuery APIs
Packages
@refinedev/core
Additional Context
No response