mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-21 23:47:56 +00:00
19 lines
566 B
TypeScript
19 lines
566 B
TypeScript
import { useState, useEffect } from 'react';
|
|
import NetInfo, { NetInfoState } from '@react-native-community/netinfo';
|
|
|
|
export function useNetworkStatus() {
|
|
const [isConnected, setIsConnected] = useState(true);
|
|
const [connectionType, setConnectionType] = useState<string>('unknown');
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = NetInfo.addEventListener((state: NetInfoState) => {
|
|
setIsConnected(state.isConnected ?? true);
|
|
setConnectionType(state.type);
|
|
});
|
|
|
|
return () => unsubscribe();
|
|
}, []);
|
|
|
|
return { isConnected, connectionType };
|
|
}
|