Skip to content

Rtk query is not exporting useQuery options types #4600

@MateuszGroth

Description

@MateuszGroth

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions