Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

enabled: false does not stop refetch()

enabled: false only pauses automatic fetching: a manual refetch() still fires, and old cached data stays visible. To make a query truly impossible, swap the query function for skipToken, and decide separately what cached data should show.

01 · Before and afterThe pattern

TypeScript
// before: "disabled", but refetch() still calls the API and old data lingers
useQuery({ queryKey, queryFn: () => getBans(ref), enabled: isSupported })

// after: no query function exists while unsupported
useQuery({ queryKey, queryFn: isSupported ? () => getBans(ref) : skipToken })
// and, if consumers must not see stale rows: return isSupported ? data : undefined

02 · Run it on your appThe check

For a feature that must never call an API in some state, does a manual refresh button also respect that rule?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.