1- import React , { useEffect , useState } from "react" ;
1+ import React from "react" ;
22import styled , { useTheme } from "styled-components" ;
3+ import { useMeasure } from "react-use" ;
34import CourtOverview from "./CourtOverview" ;
45import LatestCases from "./LatestCases" ;
56import Community from "./Community" ;
@@ -19,33 +20,25 @@ const Container = styled.div`
1920` ;
2021
2122const 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 ( ) ;
3624 const theme = useTheme ( ) ;
3725 const themeIsLight = theme . name === "light" ;
38- const breakpointIsBig = windowWidth > BREAKPOINT_SMALL_SCREEN ;
26+ const breakpointIsBig = width > BREAKPOINT_SMALL_SCREEN ;
3927 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 >
4631 ) ;
4732} ;
4833
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+
4942const Home : React . FC = ( ) => {
5043 return (
5144 < HomePageProvider timeframe = { getOneYearAgoTimestamp ( ) } >
0 commit comments