-
I am seeing that refreshOnFocus does not work in my application when my APIs are added via injectEndpoints as described here.
Observed behavior is that when a tab gets focus, the API is not refetched. I did an experiment where I moved my API endpoints into the createApi call instead of injecting it later and things started working. Is it expected behavior that refetchOnFocus doesn't work for injected endpoints? Or am I doing something wrong maybe? I didn't want to create an issue until I was sure this wasn't human error... //
// api.ts
//
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
export const api = createApi({
baseQuery: fetchBaseQuery({
baseUrl: "/api/",
}),
endpoints: () => ({}),
refetchOnMountOrArgChange: 60,
refetchOnFocus: true,
refetchOnReconnect: true
});
//
// store.ts
//
export const store = configureStore({
reducer: {
api: api.reducer,
},
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware),
});
setupListeners(store.dispatch);
//
//games.ts
//
import { api } from "./api";
import { Game } from "../games";
const gamesApi = api.injectEndpoints({
endpoints: (build) => ({
games: build.query<Game[], void>({
query: () => "games/topten",
}),
}),
});
export const { useGamesQuery } = gamesApi; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That should totally be working - and from looking at the sources at Could you provide a CodeSandbox or a Replay? |
Beta Was this translation helpful? Give feedback.
That should totally be working - and from looking at the sources at
redux-toolkit/packages/toolkit/src/query/core/buildMiddleware/windowEventHandling.ts
Line 29 in 67d41a6
Could you provide a CodeSandbox or a Replay?