1
- import React , { useEffect , useState } from "react" ;
1
+ import React from "react" ;
2
2
import styled , { useTheme } from "styled-components" ;
3
+ import { useMeasure } from "react-use" ;
3
4
import CourtOverview from "./CourtOverview" ;
4
5
import LatestCases from "./LatestCases" ;
5
6
import Community from "./Community" ;
@@ -19,33 +20,25 @@ const Container = styled.div`
19
20
` ;
20
21
21
22
const Header = ( ) => {
22
- const [ windowWidth , setWindowWidth ] = useState ( window . innerWidth ) ;
23
-
24
- useEffect ( ( ) => {
25
- const handleResize = ( ) => {
26
- setWindowWidth ( window . innerWidth ) ;
27
- } ;
28
-
29
- window . addEventListener ( "resize" , handleResize ) ;
30
-
31
- return ( ) => {
32
- window . removeEventListener ( "resize" , handleResize ) ;
33
- } ;
34
- } , [ ] ) ;
35
-
23
+ const [ ref , { width } ] = useMeasure ( ) ;
36
24
const theme = useTheme ( ) ;
37
25
const themeIsLight = theme . name === "light" ;
38
- const breakpointIsBig = windowWidth > BREAKPOINT_SMALL_SCREEN ;
26
+ const breakpointIsBig = width > BREAKPOINT_SMALL_SCREEN ;
39
27
return (
40
- < >
41
- { themeIsLight && breakpointIsBig && < HeaderLightDesktop /> }
42
- { ! themeIsLight && breakpointIsBig && < HeaderDarkDesktop /> }
43
- { themeIsLight && ! breakpointIsBig && < HeaderLightMobile /> }
44
- { ! themeIsLight && ! breakpointIsBig && < HeaderDarkMobile /> }
45
- </ >
28
+ < div ref = { ref } >
29
+ { breakpointIsBig ? < HeaderDesktop themeIsLight = { themeIsLight } /> : < HeaderMobile themeIsLight = { themeIsLight } /> }
30
+ </ div >
46
31
) ;
47
32
} ;
48
33
34
+ const HeaderDesktop : React . FC < { themeIsLight : boolean } > = ( { themeIsLight } ) => {
35
+ return themeIsLight ? < HeaderLightDesktop /> : < HeaderDarkDesktop /> ;
36
+ } ;
37
+
38
+ const HeaderMobile : React . FC < { themeIsLight : boolean } > = ( { themeIsLight } ) => {
39
+ return themeIsLight ? < HeaderLightMobile /> : < HeaderDarkMobile /> ;
40
+ } ;
41
+
49
42
const Home : React . FC = ( ) => {
50
43
return (
51
44
< HomePageProvider timeframe = { getOneYearAgoTimestamp ( ) } >
0 commit comments