The OnlineManager manages the online state within TanStack Query.
It can be used to change the default event listeners or to manually change the online state.
Its available methods are:
setEventListener can be used to set a custom event listener:
import NetInfo from '@react-native-community/netinfo' import { onlineManager } from '@tanstack/react-query' onlineManager.setEventListener(setOnline => { return NetInfo.addEventListener(state => { setOnline(!!state.isConnected) }) }) import NetInfo from '@react-native-community/netinfo' import { onlineManager } from '@tanstack/react-query' onlineManager.setEventListener(setOnline => { return NetInfo.addEventListener(state => { setOnline(!!state.isConnected) }) }) setOnline can be used to manually set the online state. Set undefined to fallback to the default online check.
import { onlineManager } from '@tanstack/react-query' // Set to online onlineManager.setOnline(true) // Set to offline onlineManager.setOnline(false) // Fallback to the default online check onlineManager.setOnline(undefined) import { onlineManager } from '@tanstack/react-query' // Set to online onlineManager.setOnline(true) // Set to offline onlineManager.setOnline(false) // Fallback to the default online check onlineManager.setOnline(undefined) Options
isOnline can be used to get the current online state.
const isOnline = onlineManager.isOnline() const isOnline = onlineManager.isOnline() 