Skip to content

Commit 88bf03f

Browse files
committed
fix: resolve SSR hydration mismatch in useOnlineStatus hook
1 parent ffdc8a7 commit 88bf03f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/hooks/useOnlineStatus.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import { useState, useEffect } from 'react';
44

55
export function useOnlineStatus(): boolean {
6-
const [isOnline, setIsOnline] = useState(
7-
typeof navigator !== 'undefined' ? navigator.onLine : true
8-
);
6+
// Always initialize to true to match SSR and prevent hydration mismatches
7+
const [isOnline, setIsOnline] = useState(true);
98

109
useEffect(() => {
10+
// Sync with the actual browser status on mount
11+
setIsOnline(typeof navigator !== 'undefined' ? navigator.onLine : true);
1112
const handleOnline = () => setIsOnline(true);
1213
const handleOffline = () => setIsOnline(false);
1314

0 commit comments

Comments
 (0)