File tree 3 files changed +16
-9
lines changed
3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ const Cart = ({ stickyNav }: ICartProps) => {
50
50
51
51
{ productCount && (
52
52
< 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
54
54
${ stickyNav ? 'text-black bg-white' : 'text-white bg-black' } ` }
55
55
>
56
56
{ productCount }
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ interface IHeaderProps {
16
16
const Header = ( { title } : IHeaderProps ) => (
17
17
< >
18
18
< Head >
19
- < title > Next.js webshop with WooCommerce { title } </ title >
19
+ < title > { ` Next.js webshop with WooCommerce $ {title } ` } </ title >
20
20
< meta name = "description" content = "WooCommerce webshop" />
21
21
< meta name = "keywords" content = "Ecommerce, WooCommerce" />
22
22
< meta
Original file line number Diff line number Diff line change 1
- import { useLayoutEffect , useState } from 'react' ;
1
+ import { useEffect , useState } from 'react' ;
2
2
import debounce from 'lodash/debounce' ;
3
3
4
4
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 ) ;
6
7
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 => {
9
13
setIsMobile ( window . innerWidth < 768 ) ;
10
- } ;
11
- window . addEventListener ( 'resize' , debounce ( updateSize , 250 ) ) ;
14
+ } , 250 ) ;
15
+
16
+ // Initial check
12
17
updateSize ( ) ;
13
18
19
+ window . addEventListener ( 'resize' , updateSize ) ;
14
20
return ( ) : void => window . removeEventListener ( 'resize' , updateSize ) ;
15
21
} , [ ] ) ;
16
22
17
- return isMobile ;
23
+ // Return false during SSR, actual value after hydration
24
+ return isMobile ?? false ;
18
25
} ;
19
26
20
27
export default useIsMobile ;
You can’t perform that action at this time.
0 commit comments