Я переписал, даже скопировал этот код с официальной документации RTK Query и мне выдает эту ошибку, как исправить?
Вот ссылка на ту документацию -
https://redux-toolkit.js.org/rtk-query/overview
Вот код:
// pokemonApi.js
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query"
export const pokemonApi = createApi({
reducerPath: 'pokemonApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
endpoints: (builder) => ({
getPokemonByName: builder.query({
query: (name) => `pokemon/${name}`,
}),
}),
})
export const { useGetPokemonByNameQuery } = pokemonApi
// store.js
import { setupListeners } from "@reduxjs/toolkit/query"
import { pokemonApi } from "./pokemonApi"
import { configureStore } from "@reduxjs/toolkit"
export const store = configureStore({
reducer: {
[pokemonApi.reducerPath]: pokemonApi.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(pokemonApi.middleware),
})
setupListeners(store.dispatch)
// Test.jsx
import { useGetPokemonByNameQuery } from "./pokemonApi";
function Test() {
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur')
return (
<div>
sdaasdasd
</div>
);
}
export default Test;
Ошибка:
Test.jsx:4 Uncaught TypeError: useGetPokemonByNameQuery is not a function
at Test (Test.jsx:4:38)
at renderWithHooks (react-dom_client.js?v=4725db46:11568:26)
at mountIndeterminateComponent (react-dom_client.js?v=4725db46:14946:21)
at beginWork (react-dom_client.js?v=4725db46:15934:22)
at HTMLUnknownElement.callCallback2 (react-dom_client.js?v=4725db46:3674:22)
at Object.invokeGuardedCallbackDev (react-dom_client.js?v=4725db46:3699:24)
at invokeGuardedCallback (react-dom_client.js?v=4725db46:3733:39)
at beginWork$1 (react-dom_client.js?v=4725db46:19793:15)
at performUnitOfWork (react-dom_client.js?v=4725db46:19226:20)
at workLoopSync (react-dom_client.js?v=4725db46:19165:13)