TypeError: inject.endpoints is not a function
TypeError: inject.endpoints is not a function
我正在阅读 RTK Query Quick Start tutorial 并在 javascript 中尝试它,而 运行 它向我显示了这个错误。
相应站点上的示例同时显示了 Typescript 和 Javascript 代码,但沙箱示例使用的是 typescript。
src/app/services/pokemon.js
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const pokemonApi = createApi({
reducerPath:'pokemonApi',
baseQuery: fetchBaseQuery({
baseUrl: 'https://pokeapi.co/api/v2'
}),
enedpoints: (builder)=>({
getPokemonByName: builder.query({
query:(name)=>`pokemon/${name}`,
}),
}),
});
export const { useGetPokemonByNameQuery } = pokemonApi
src/app.jsx
import { useGetPokemonByNameQuery } from './services/pokemon';
export default function App(){
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur');
return (
<div className="App">
{error ? (
<>Oh no, there was an error</>
) : isLoading ? (
<>Loading...</>
) : data ? (
<>
<h3>{data.species.name}</h3>
<img src={data.sprites.front_shiny} alt={data.species.name} />
</>
) : null}
</div>
);
}
src/app/store.js
import { configureStore } from "@reduxjs/toolkit";
import { setupListeners } from "@reduxjs/toolkit/dist/query";
import counterReducer from "../features/counter/counterSlice";
import { pokemonApi } from "../services/pokemon";
export const store = configureStore({
reducer:{
counter: counterReducer,
[pokemonApi.reducerPath]: pokemonApi.reducer,
},
middleware: (getDefaultMiddleware)=>
getDefaultMiddleware().concat(pokemonApi.middleware),
});
// optional, but required for refetchOnFocus/refetchOnReconnect behaviors
// see `setupListeners` docs - takes an optional callback as the 2nd arg for customization
setupListeners(store.dispatch)
你打错了。 enedpoints
而不是 endpoints
.
我正在阅读 RTK Query Quick Start tutorial 并在 javascript 中尝试它,而 运行 它向我显示了这个错误。
相应站点上的示例同时显示了 Typescript 和 Javascript 代码,但沙箱示例使用的是 typescript。
src/app/services/pokemon.js
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const pokemonApi = createApi({
reducerPath:'pokemonApi',
baseQuery: fetchBaseQuery({
baseUrl: 'https://pokeapi.co/api/v2'
}),
enedpoints: (builder)=>({
getPokemonByName: builder.query({
query:(name)=>`pokemon/${name}`,
}),
}),
});
export const { useGetPokemonByNameQuery } = pokemonApi
src/app.jsx
import { useGetPokemonByNameQuery } from './services/pokemon';
export default function App(){
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur');
return (
<div className="App">
{error ? (
<>Oh no, there was an error</>
) : isLoading ? (
<>Loading...</>
) : data ? (
<>
<h3>{data.species.name}</h3>
<img src={data.sprites.front_shiny} alt={data.species.name} />
</>
) : null}
</div>
);
}
src/app/store.js
import { configureStore } from "@reduxjs/toolkit";
import { setupListeners } from "@reduxjs/toolkit/dist/query";
import counterReducer from "../features/counter/counterSlice";
import { pokemonApi } from "../services/pokemon";
export const store = configureStore({
reducer:{
counter: counterReducer,
[pokemonApi.reducerPath]: pokemonApi.reducer,
},
middleware: (getDefaultMiddleware)=>
getDefaultMiddleware().concat(pokemonApi.middleware),
});
// optional, but required for refetchOnFocus/refetchOnReconnect behaviors
// see `setupListeners` docs - takes an optional callback as the 2nd arg for customization
setupListeners(store.dispatch)
你打错了。 enedpoints
而不是 endpoints
.