Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RTK Query autogenerated hooks do not exist

I started a project recently and I use redux/toolkit and its queries API to manage my data.

I tried to use the auto-generated hooks but I get an error from typescript saying they cant find them. Here’s an example of code I wrote:

export const elementsApi = api.injectEndpoints({
  endpoints: (build) => ({
    getElements: build.query<
      {
        rootParentId: string;
      } & GetElementReturnType,
      number
    >({
      query: (search) => ({ url: `Menu/GetFiles${search}` }),
      transformResponse: ({ data }: { data: BackendMenuType }) => {
        return {
          rootParentId: data.MenuId,
          ...getElements(data),
        };
      },
      providesTags: (result, _error, id) => [{ type: elements, id }],
    }),
  }),
});

export const { useGetElementsQuery } = elementsApi;

The error message I get when I try to get the hook :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Property 'useGetElementsQuery' does not exist on type 'Api<BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, { getElements: QueryDefinition<number, BaseQueryFn<...>, string, { ...; } & GetElementReturnType, "api">; }, "api", string, unique symbol>'.

I made sure my VSCode was set to a version higher than 4.1+, as suggested by this issue.
It is 5.0.4

the typescript version installed in my devdependencies is also 5.0.4

Is there another thing I forgot to check?

>Solution :

You probably imported createApi from @reduxjs/toolkit/query, not @reduxjs/toolkit/query/react – so you used the non-hook version.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading