Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Header/Cart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Cart = ({ stickyNav }: ICartProps) => {

{productCount && (
<span
className={`w-6 h-6 pb-2 -mt-5 text-center rounded-full
className={`w-6 h-6 pb-2 -mt-5 !ml-auto text-center rounded-full
${stickyNav ? 'text-black bg-white' : 'text-white bg-black'}`}
>
{productCount}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface IHeaderProps {
const Header = ({ title }: IHeaderProps) => (
<>
<Head>
<title>Next.js webshop with WooCommerce {title}</title>
<title>{`Next.js webshop with WooCommerce ${title}`}</title>
<meta name="description" content="WooCommerce webshop" />
<meta name="keywords" content="Ecommerce, WooCommerce" />
<meta
Expand Down
21 changes: 14 additions & 7 deletions src/utils/hooks/useIsMobile.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { useLayoutEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import debounce from 'lodash/debounce';

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

useLayoutEffect(() => {
const updateSize = (): void => {
useEffect(() => {
// Skip effect on server side
if (typeof window === 'undefined') return;

const updateSize = debounce((): void => {
setIsMobile(window.innerWidth < 768);
};
window.addEventListener('resize', debounce(updateSize, 250));
}, 250);

// Initial check
updateSize();

window.addEventListener('resize', updateSize);
return (): void => window.removeEventListener('resize', updateSize);
}, []);

return isMobile;
// Return false during SSR, actual value after hydration
return isMobile ?? false;
};

export default useIsMobile;
Loading