我的useGetProductsQuery
由于某种原因没有被认可。
产品ApiSlice.js
import { PRODUCTS_URL } from "../constants";
import { apiSlice } from "./apiSlice";
export const productsApiSlice = apiSlice.injectEndpoints({
endpoints: (builder) => ({
getProducts: builder.query({
query: () => ({
url: PRODUCTS_URL,
}),
keepUnusedDataFor: 5,
}),
}),
});
export const { useGetProductsQuery } = productsApiSlice;
成分:
import { useGetProductsQuery } from "../slices/productsApiSlice";
function HomeScreen() {
const { data: products, isLoading, error } = useGetProductsQuery();
return (
<div className="row">
{isLoading ? (
<h2>Loading...</h2>
) : error ? (
<div>{error?.data?.message || error.error}</div>
) : (
<p>test</p>
)}
</div>
);
}
我收到以下错误:
(0 , _slices_productsApiSlice__WEBPACK_IMPORTED_MODULE_0__.useGetProductsQuery) is not a function
TypeError: (0 , _slices_productsApiSlice__WEBPACK_IMPORTED_MODULE_0__.useGetProductsQuery) is not a function