i got this error ts(2742) cannot be named without a reference for all rtk query actions, how i can fix it?
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
export const postsApi = createApi({
reducerPath: "api",
baseQuery: fetchBaseQuery({ baseUrl: "url" }),
endpoints: (builder) => ({
getChaptersList: builder.query({
query: () => "/chapters-list/",
}),
getChapter: builder.query({
query: (chapter:string) => `/chapters-list/${chapter}/`,
}),
}),
});
export const {
useGetChaptersListQuery,
useGetChapterQuery
} = postsApi;
The inferred type of 'useGetChapterQuery' cannot be named without a reference to '../../../node_modules/@reduxjs/toolkit/dist/query/react/buildHooks'. This is likely not portable. A type annotation is necessary.ts(2742)
2
Answers
Am used vite latest version, i set a little older vite version and now i don't have this ts error :]
there are two solutions.
1st:
assert "any" type while exporting from the Redux API file:
export const { useLoginMutation, useSignUpMutation } = baseApi as any;
2nd:
You can export baseApi and call the hooks like this:
import baseApi from ‘../redux/api/baseApi’;
const [login] = baseApi.useLoginMutation();