1
- import React , { useState , useRef } from 'react'
1
+ import React , { useState , useEffect , useRef } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import clsx from 'clsx'
4
4
import useComponentSize from '@rehooks/component-size'
@@ -19,19 +19,23 @@ const DashboardLayout = (
19
19
} ,
20
20
) => {
21
21
const refHeaderContainer = useRef ( null )
22
- // const refSidebarContainer = useRef(null)
23
- // const refFooterContainer = useRef(null)
24
22
25
23
const classes = useStyles ( )
26
24
const theme = useTheme ( )
27
25
const isDesktop = useMediaQuery ( theme . breakpoints . up ( 'md' ) )
28
26
const isMobile = ! isDesktop
29
27
28
+ const [ headerHeight , setHeaderHeight ] = useState ( 0 )
30
29
const [ isSidebarOpenMobile , setIsSidebarOpenMobile ] = useState ( false )
31
30
const [ isSidebarOpenDesktop , setIsSidebarOpenDesktop ] = useState ( true )
32
31
const [ isSidebarCollapsed , setIsSidebarCollapsed ] = useState ( false )
33
32
34
- const headerSize = useComponentSize ( refHeaderContainer )
33
+ useEffect ( ( ) => {
34
+ // code to run on component mount
35
+ setHeaderHeight ( refHeaderContainer . current . offsetHeight )
36
+ } , [ ] )
37
+
38
+ // const headerSize = useComponentSize(refHeaderContainer)
35
39
// const sidebarSize = useComponentSize(refSidebarContainer)
36
40
// const footerSize = useComponentSize(refFooterContainer)
37
41
@@ -116,7 +120,7 @@ const DashboardLayout = (
116
120
< main
117
121
className = { classes . mainContainer }
118
122
style = { {
119
- paddingTop : headerSize . height ,
123
+ paddingTop : headerHeight , // || headerSize.height,
120
124
} }
121
125
>
122
126
< div className = { classes . contentContainer } > { children } </ div >
@@ -184,10 +188,10 @@ const useStyles = makeStyles(theme => ({
184
188
drawer : {
185
189
width : '100%' ,
186
190
position : 'absolute' ,
187
- // [theme.breakpoints.up('md ')]: {
188
- // width: theme.sidebar.width,
189
- // flexShrink: 0,
190
- // },
191
+ [ theme . breakpoints . down ( 'sm ') ] : {
192
+ width : theme . sidebar . width ,
193
+ flexShrink : 0 ,
194
+ } ,
191
195
} ,
192
196
mainContainer : {
193
197
flexGrow : 1 ,
0 commit comments