polling interval of rtk query is not working
Asked Answered
W

1

6

I'm in the process of implementing rtk-query and am having problems with the polling feature of the library.

### 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,
  });

  ...
}

The query works fine once, however subsequent polling requests are not sent. In the docs it makes it seem simple, however it looks like I'm missing something. Please let me know any other information that would be useful for helping to find the solution.

EDIT: Here was the middleware that was setup incorrectly:

const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware({
    serializableCheck: {
      ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
    },
    ...api.middleware,
  }),
});
Wightman answered 3/2, 2022 at 16:43 Comment(1)
I would assume you forgot to add the middleware for your api to the store.Nemhauser
W
4

Thanks to the comment from @phry, the middleware was setup incorrectly.

import { api } from "service";

const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware({
    serializableCheck: {
      ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
    },
  }).concat(api.middleware),
});
Wightman answered 4/2, 2022 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.