
The OnlineManager manages the online state within React Query.
It can be used to change the default event listeners or to manually change the online state.
Its available methods are:
onlineManager.setEventListenersetEventListener can be used to set a custom event listener:
import NetInfo from '@react-native-community/netinfo'import { onlineManager } from 'react-query'onlineManager.setEventListener(setOnline => {return NetInfo.addEventListener(state => {setOnline(state.isConnected)})})
onlineManager.setOnlinesetOnline can be used to manually set the online state. Set undefined to fallback to the default online check.
import { onlineManager } from 'react-query'// Set to onlineonlineManager.setOnline(true)// Set to offlineonlineManager.setOnline(false)// Fallback to the default online checkonlineManager.setOnline(undefined)
Options
online: boolean | undefinedonlineManager.isOnlineisOnline can be used to get the current online state.
const isOnline = onlineManager.isOnline()
The latest TanStack news, articles, and resources, sent to your inbox.