Skip to content

Commit 96bd57c

Browse files
authored
Merge pull request #1387 from w3bdesign/develop
Fix warning
2 parents 9424433 + d087356 commit 96bd57c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/components/Header/Cart.component.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const Cart = ({ stickyNav }: ICartProps) => {
5050

5151
{productCount && (
5252
<span
53-
className={`w-6 h-6 pb-2 -mt-5 text-center rounded-full
53+
className={`w-6 h-6 pb-2 -mt-5 !ml-auto text-center rounded-full
5454
${stickyNav ? 'text-black bg-white' : 'text-white bg-black'}`}
5555
>
5656
{productCount}

src/components/Header/Header.component.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface IHeaderProps {
1616
const Header = ({ title }: IHeaderProps) => (
1717
<>
1818
<Head>
19-
<title>Next.js webshop with WooCommerce {title}</title>
19+
<title>{`Next.js webshop with WooCommerce ${title}`}</title>
2020
<meta name="description" content="WooCommerce webshop" />
2121
<meta name="keywords" content="Ecommerce, WooCommerce" />
2222
<meta

src/utils/hooks/useIsMobile.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
import { useLayoutEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import debounce from 'lodash/debounce';
33

44
const useIsMobile = (): boolean => {
5-
const [isMobile, setIsMobile] = useState(false);
5+
// Initialize with null to avoid hydration mismatch
6+
const [isMobile, setIsMobile] = useState<boolean | null>(null);
67

7-
useLayoutEffect(() => {
8-
const updateSize = (): void => {
8+
useEffect(() => {
9+
// Skip effect on server side
10+
if (typeof window === 'undefined') return;
11+
12+
const updateSize = debounce((): void => {
913
setIsMobile(window.innerWidth < 768);
10-
};
11-
window.addEventListener('resize', debounce(updateSize, 250));
14+
}, 250);
15+
16+
// Initial check
1217
updateSize();
1318

19+
window.addEventListener('resize', updateSize);
1420
return (): void => window.removeEventListener('resize', updateSize);
1521
}, []);
1622

17-
return isMobile;
23+
// Return false during SSR, actual value after hydration
24+
return isMobile ?? false;
1825
};
1926

2027
export default useIsMobile;

0 commit comments

Comments
 (0)