src/Service/Post.js
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query"
export const postAPi=createApi({
reducerPath:'postApi',
baseQuery:fetchBaseQuery({
baseUrl:"https://jsonplaceholder.typicode.com/",
}),
endpoints:(builder)=>({
getAllPost:builder.query({
query:()=>({
url:'posts',
method:'GET'
})
})
})
})
export const { useGetAllPostQuery }=postAPi
src/App.js
import { useGetAllPostQuery } from './Service/Post'
export default function App() {
const data=useGetAllPostQuery()
return (
<div>
<h1>
React App
</h1>
</div>
)
}
我使用 RTK 查询获取数据,所以,当我尝试在我的 app.js 反应组件中访问 useGetAllPostQuery 时,它在浏览器中看到我的错误 TypeError: Object(...) is not a function 所以,任何人都可以建议如何解决这个错误