readux工具包查询中的EnhanceEndPoints()在做什么?
根据官方redux工具包官方查询文档(以获取EnhanceEndpoints) ):
与注射点不同,部分端点定义不会 替换现有的定义,但在 每次定义基础(即,object.Assign) newPartialEndPoint))。
我们不能对以下内容执行此操作?
api.injectEndpoints({ overrideExisting: false, endpoints:...})
那么,为什么我们需要额外的API呢?
另外,我注意到那里给出的示例:
import { api } from './api'
const enhancedApi = api.enhanceEndpoints({
addTagTypes: ['User'],
endpoints: {
getUserByUserId: {
providesTags: ['User'],
},
patchUserByUserId: {
invalidatesTags: ['User'],
},
// alternatively, define a function which is called with the endpoint definition as an argument
getUsers(endpoint) {
endpoint.providesTags = ['User']
endpoint.keepUnusedDataFor = 120
},
},
})
...不使用
...(builder)=>...builder.query(...)...
这是某种替代语法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OverrideExisting:
injectEndEndPoints 的false 表示,如果端点已经存在,则会收到一个错误消息,而端点也不会发生。如果true
,它将替换您现有的端点。=>
InjectEndPoints
可以用全新的代码添加或替换端点,但是它无法修改端点定义。EnhanceEndpoints
另一方面无法创建一个新的端点定义 - 但它允许您修改现有的定义。It has two notations:
无论哪种方式:如果该端点以前不存在,则不会发生任何事情。
overrideExisting: false
ofinjectEndpoints
means that if the endpoint already exists, you get an error message and nothing happens to the endpoint. Iftrue
, it will replace your existing endpoint.=>
injectEndpoints
can add or replace endpoints with completely new code, but it cannot modify an endpoint definition.enhanceEndpoints
on the other hand cannot create a new endpoint definition - but it allows you to modify an existing one.It has two notations:
Either way: if that endpoint did not exist before, nothing will happen.