-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
The options type is something that should be exported
I implemented the following method to create a useQuery hook with default options, as the library does not provide a way to define the refetchOnMountOrArgChange option at the query level:
export const getUseQueryHookWithDefaultOptions =
<
D extends QueryDefinition<any, any, any, any> = QueryDefinition<
any,
any,
any,
any
>,
>(
useQueryHook: UseQuery<D>,
defaultOptions: DistributiveOmit<
SubscriptionOptions & UseQueryStateOptions<D, ReturnType<UseQuery<D>>>,
"selectFromResult" | "skip"
> & { refetchOnMountOrArgChange?: number | boolean },
): UseQuery<D> =>
(arg, options) => {
return useQueryHook(arg, { ...defaultOptions, ...options });
};
usage
export const useGetPostsQuery =
getUseQueryHookWithDefaultOptions(
postsApi.useGetPostsQuery
{ refetchOnMountOrArgChange: false },
);
But with the latest update - @2.2.7
, the SubscriptionOptions
and UseQueryStateOptions
types are no longer exported
- I am willing to open a pr to export them :)
Metadata
Metadata
Assignees
Labels
No labels