rtk 查询的轮询间隔不起作用
polling interval of rtk query is not working
我正在实施 rtk-query 并且遇到了库的 polling 功能的问题。
### service.js
export const api = createApi({
...,
endpoints: (builder) => ({
getBlockPurchase: builder.query({
query: (id) => `block-purchases/${id}/`,
}),
}),
});
### component.js
function BlockPurchaseComponent({ blockPurchaseId }) {
const { data, error } = useGetBlockPurchaseQuery(blockPurchaseId, {
pollingInterval: 3000,
});
...
}
查询一次正常,但后续轮询请求不发送。在文档中它看起来很简单,但看起来我遗漏了一些东西。请让我知道有助于找到解决方案的任何其他信息。
编辑:
这是设置不正确的中间件:
const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
...api.middleware,
}),
});
感谢@phry 的评论,中间件设置不正确。
import { api } from "service";
const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}).concat(api.middleware),
});
我正在实施 rtk-query 并且遇到了库的 polling 功能的问题。
### service.js
export const api = createApi({
...,
endpoints: (builder) => ({
getBlockPurchase: builder.query({
query: (id) => `block-purchases/${id}/`,
}),
}),
});
### component.js
function BlockPurchaseComponent({ blockPurchaseId }) {
const { data, error } = useGetBlockPurchaseQuery(blockPurchaseId, {
pollingInterval: 3000,
});
...
}
查询一次正常,但后续轮询请求不发送。在文档中它看起来很简单,但看起来我遗漏了一些东西。请让我知道有助于找到解决方案的任何其他信息。
编辑: 这是设置不正确的中间件:
const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
...api.middleware,
}),
});
感谢@phry 的评论,中间件设置不正确。
import { api } from "service";
const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}).concat(api.middleware),
});