fix(ssr-navigator): resolve ReferenceError navigator is not defined during Next.js static prerendering in useNetworkStatus hook
This commit is contained in:
1 parent
eb6318ecc1
commit
dac41b14ee
2 files changed
+6
-2
No files matched your search
@@ -1,9 +1,13 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function useNetworkStatus() {
|
||||
const [isOnline, setIsOnline] = useState(navigator.onLine);
|
||||
const [isOnline, setIsOnline] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined' && typeof navigator !== 'undefined') {
|
||||
setIsOnline(navigator.onLine);
|
||||
}
|
||||
|
||||
const handleOnline = () => setIsOnline(true);
|
||||
const handleOffline = () => setIsOnline(false);
|
||||
|
||||
|
||||
Reference in new issue
Block a user