canina/src/hooks/useNetworkStatus.ts
parsa aghayi c95c9e5ce0 feat: initialize project structure
- Configure project metadata and dependencies
- Setup Vite with React and TypeScript
- Add environment configuration and .gitignore
- Implement initial application entry point and assets
2026-05-26 11:37:22 +03:30

21 lines
554 B
TypeScript

import { useState, useEffect } from 'react';
export function useNetworkStatus() {
const [isOnline, setIsOnline] = useState(navigator.onLine);
useEffect(() => {
const handleOnline = () => setIsOnline(true);
const handleOffline = () => setIsOnline(false);
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
}, []);
return isOnline;
}