具有两个不同api的RTK查询只适用于一个



我有两个不同的Api。两者都使用RTK查询来执行不同的CRUD操作集。其中一个运行正常但另一个显示错误

TypeError: (0 , _api_addressApi__WEBPACK_IMPORTED_MODULE_2__.useGetAddress) is not a 
function

这是我的addressApi.js不工作

import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
export const addressApi = createApi({
reducerPath: "address",
baseQuery: fetchBaseQuery({
baseUrl: "https://random-data-api.com/api/v2",
}),
endpoints: (builder) => ({
getAddress: builder.query({
query: () => {
return { url: "/addresses" };
},
}),
}),
});
export const { useGetAddress } = addressApi;
这是我的store.js
import { configureStore } from "@reduxjs/toolkit";
import { addressApi } from "../api/addressApi";
import { destinationApi } from "../api/destinationApi";
export const store = configureStore({
reducer: {
// destinationApi works but addressApi does not works
[destinationApi.reducerPath]: destinationApi.reducer,
[addressApi.reducerPath]: addressApi.reducer,
},
// Adding the api middleware enables caching, invalidation, polling,
// and other useful features of `rtk-query`.
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware()
.concat(destinationApi.middleware)
.concat(addressApi.middleware),
});

在我调用useGetAddress()的文件中

import { useGetAddress } from "../api/addressApi";
function AddDestination() {
....
const { data, error } = useGetAddress();
console.log(data);

提供查询方法:'GET'

getAddress: builder.query({
query: () => {
return { url: "/addresses" ,
method:'GET',
};
},

相关内容

  • 没有找到相关文章

最新更新