Closed
Description
Hey there,
in my application, I want to wrap the default useQuery
hook with some custom functionality so that I can use this functionality in my whole application.
It should look something like this
import type { QueryDefinition } from '@reduxjs/toolkit/dist/query/endpointDefinitions';
import type { UseQueryState } from '@reduxjs/toolkit/dist/query/react/buildHooks';
const wrapUseQuery = <TQuery extends UseQueryState<QueryDefinition<any, any, any, any>>>(useQuery: TQuery): TQuery => {
return (parameter, options) => {
const queryResult = useQuery(parameter, options);
// do some other stuff that involves other hooks like `useState` and `useEffect`
return queryResultEnhanced;
}
}
The thing is that useQuery
itself is generic (because of the selectFromResult
option). I want to keep that logic. Hence my inner signature needs to look something like this:
return <TResult extends Record<string, any> = UseQueryStateDefaultResult<D>>(parameter, options) => {
// ...
}
but UseQueryStateDefaultResult
is not exposed by RTK query (see https://github.com/reduxjs/redux-toolkit/blob/v1.8.3/packages/toolkit/src/query/react/buildHooks.ts#L371 - there is no export
for the type).
Since this is a very complex type, I would rather import it from the library that duplicate it into my code base.
Is there a reason why this type is not exposed to the public?
Metadata
Metadata
Assignees
Labels
No labels