OnlineManager
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.setEventListener
setEventListener can be used to set a custom event listener:
TypeScript
1import NetInfo from '@react-native-community/netinfo'2import { onlineManager } from '@tanstack/react-query'3 4onlineManager.setEventListener(setOnline => {5 return NetInfo.addEventListener(state => {6 setOnline(!!state.isConnected)7 })8})onlineManager.setOnline
setOnline can be used to manually set the online state. Set undefined to fallback to the default online check.
TypeScript
1import { onlineManager } from '@tanstack/react-query'2 3// Set to online4onlineManager.setOnline(true)5 6// Set to offline7onlineManager.setOnline(false)8 9// Fallback to the default online check10onlineManager.setOnline(undefined)Options
online: boolean | undefined
onlineManager.isOnline
isOnline can be used to get the current online state.
TypeScript
1const isOnline = onlineManager.isOnline()