Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

useOfflineIndicator.tsx

21 lines508 Bytes

1import { onlineManager } from '@tanstack/react-query'
2import { useEffect } from 'react'
3import toast from 'react-hot-toast'
4​
5export function useOfflineIndicator() {
6 useEffect(() => {
7 return onlineManager.subscribe(() => {
8 if (onlineManager.isOnline()) {
9 toast.success('online', {
10 id: 'ReactQuery',
11 duration: 2000,
12 })
13 } else {
14 toast.error('offline', {
15 id: 'ReactQuery',
16 duration: Infinity,
17 })
18 }
19 })
20 }, [])