import { useNetInfo } from '@react-native-community/netinfo'; const useAppNetworkInfo = () => { const netInfo = useNetInfo(); const count = useRef(0); const isConnected = useRef(false); useEffect(() => { if (count.current > -1) { if (netInfo?.isConnected && netInfo?.isInternetReachable) { if (!isConnected.current) { if (count.current > 2) { Toast.success(i18next.t('global.onlineAlert', 10)); } } const socket = GlobalLib.SocketClient.get(); if (socket && typeof socket.open === 'function') { socket.open(); } isConnected.current = true; } else { if (isConnected.current) { Toast.offline(i18next.t('global.offlineAlert', 10)); } isConnected.current = false; } } count.current = count.current + 1; }, [netInfo]); };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter