question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rtk-query: Modify refetchOnMountOrArgChange with enhanceEndpoints

See original GitHub issue

I’m using codegen to generate the api spec and would like to specify a refetchOnMountOrArgChange for the whole endpoint - rather than in every component.

Ideally I’d like to do something like

import { injectedApi } from './generated/api'

const enhancedRtkApi = injectedApi.enhanceEndpoints({
    getData: {
      refetchOnMountOrArgChange: 600,
      keepUnusedDataFor: 14400,
    },
  },
})
export { enhancedRtkApi as api }

But it looks like refetchOnMountOrArgChange is part of the query key. I may be missing something, but I couldn’t figure out a way to pass query key w/o overriding the generated one

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
phryneascommented, May 17, 2022

Yeah I re-checked the source - you can either define it for the full api, or on the hook call, but not on the endpoint. My bad.

1reaction
ericecookcommented, May 17, 2022

I’m getting a TS error with that:

Argument of type '{ query: () => { url: string; }; refetchOnMountOrArgChange: number; }' is not assignable to parameter of type 'Omit<EndpointDefinitionWithQuery<void, BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, {}>, DataResponse> & { ...; } & { ...; } & QueryExtraOptions<...>, "type"> | Omit<...>'.
  Object literal may only specify known properties, and 'refetchOnMountOrArgChange' does not exist in type 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Redux Toolkit
RTK Query > Usage > Queries: fetching data from a server. ... Query endpoints may also modify the response contents before the result...
Read more >
RTK Query Best Practices - Medium
RTK Query is responsible for: Fetching data and keeping cached data on the client-side. Mutating data (create/update/delete) and syncing the changes from the ......
Read more >
Introduction to Redux Toolkit Query with TypeScript
On top of that, RTK Query generates React hooks ready to use. ... When we want to alter the data on the server,...
Read more >
redux-starter-kit - Bountysource
Investigate RTK Query-specific additions to the Redux DevTools Extension $ 0 ... enhanceEndpoints({ getData: { refetchOnMountOrArgChange: 600, ...
Read more >
What argument must change in order for refetching to occur ...
To quote the official Redux Toolkit Query documentation for 'refetchOnMountOrArgChange' here: I.e., when the component calling ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found