Open alikashan opened 2 months ago
if isOffline
changes, you are throwing away the cache and create a new one. Even if this works, it isn't good. Creating a queryClient in useMemo
is also "wrong" because again, re-creating the cache from scratch isn't what you want.
I would not close over isOffline
and create a new function / cache every time it changes, but rather provide an imperative way to read that value.
Not sure how useOfflineMode
is implemented, but if it's e.g. a zustand store, you could just do store.getState().isOffline
as an imperative action inside the onError
callback.
Describe the bug
Offline mode feature in React native Typescript Application.
There is switch view in my Settings screen where user can switch to offline mode and this switch is bind with React Context. the only requirement is to disable all error toasts when offline mode is enabled but the problem is
queryCache.onError
callback always reflects the initial value of context ieisOffline
value is always false insideonError
callback regardless of user action on switch.Your minimal, reproducible example
Steps to reproduce
call
refetch
function on any screen focus.This is my minimal reproducible code with simple QueryClient object
Expected behavior
onError should reflect the correct state value
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Android IOS
Tanstack Query adapter
react-query
TanStack Query version
v5.29.2
TypeScript version
v5.4.5
Additional context
No response