Skip to content
0

katanakit-js / OnlineManager

Interface: OnlineManager ​

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:14

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.

By default, the onlineManager assumes an active network connection, and listens to the online and offline events on the window object to detect changes.

Extends ​

  • Subscribable<Listener>

Properties ​

PropertyModifierTypeInherited fromDefined in
listenersprotectedSet<Listener>Subscribable.listenersnode_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:8

Methods ​

hasListeners() ​

ts
hasListeners(): boolean;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:28

Returns true while at least one listener is registered, false once they have all unsubscribed.

Returns ​

boolean

Inherited from ​

ts
Subscribable.hasListeners

isOnline() ​

ts
isOnline(): boolean;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:56

isOnline can be used to get the current online state.

Returns ​

boolean


onSubscribe() ​

ts
protected onSubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:17

Returns ​

void

Overrides ​

ts
Subscribable.onSubscribe

onUnsubscribe() ​

ts
protected onUnsubscribe(): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:18

Returns ​

void

Overrides ​

ts
Subscribable.onUnsubscribe

setEventListener() ​

ts
setEventListener(setup): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:37

setEventListener can be used to set a custom event listener that will be used to determine the online state. The provided setup function receives a setOnline callback that should be called with a boolean whenever the online state changes.

Parameters ​

ParameterType
setupSetupFn

Returns ​

void

Example ​

ts
import NetInfo from '@react-native-community/netinfo'
import { onlineManager } from '@tanstack/query-core'

onlineManager.setEventListener((setOnline) => {
  return NetInfo.addEventListener((state) => {
    setOnline(!!state.isConnected)
  })
})

setOnline() ​

ts
setOnline(online): void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/onlineManager.d.ts:52

setOnline can be used to manually set the online state.

Parameters ​

ParameterType
onlineboolean

Returns ​

void

Example ​

ts
import { onlineManager } from '@tanstack/query-core'

// Set to online
onlineManager.setOnline(true)

// Set to offline
onlineManager.setOnline(false)

subscribe() ​

ts
subscribe(listener): () => void;

Defined in: node_modules/.bun/@tanstack+query-core@5.104.1/node_modules/@tanstack/query-core/build/modern/subscribable-CysQ0tne.d.ts:24

Registers a listener to be called on every update this object notifies about. Returns a function that removes the listener again — call it to stop listening. The base class never drops a listener on its own, though some subclasses clear all of theirs in destroy().

Parameters ​

ParameterTypeDescription
listenerListenerCalled on each update, with whatever the subclass passes to its subscribers.

Returns ​

() => void

Example ​

ts
const unsubscribe = subscribable.subscribe(() => {
  // react to the update
})

unsubscribe()

Inherited from ​

ts
Subscribable.subscribe

Released under the MIT License.