Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rtk query is not exporting useQuery options types #4600

Open
1 task done
MateuszGroth opened this issue Sep 3, 2024 · 1 comment · May be fixed by #4604
Open
1 task done

Rtk query is not exporting useQuery options types #4600

MateuszGroth opened this issue Sep 3, 2024 · 1 comment · May be fixed by #4604

Comments

@MateuszGroth
Copy link

MateuszGroth commented Sep 3, 2024

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 :)
@aryaemami59 aryaemami59 linked a pull request Sep 4, 2024 that will close this issue
5 tasks
@aryaemami59
Copy link
Contributor

aryaemami59 commented Sep 4, 2024

The SubscriptionOptions type is already exported and I just put up #4604 which exports UseQueryStateOptions.

Correction: #4604 adds a TypedUseQueryStateOptions helper type which Provides a way to define a "pre-typed" version of UseQueryStateOptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants