File tree Expand file tree Collapse file tree 3 files changed +31
-20
lines changed Expand file tree Collapse file tree 3 files changed +31
-20
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { css, jsx } from '@emotion/core'
33
44const styles = {
55 divider : {
6+ width : '100%' ,
67 backgroundColor : '#e8e8e8' ,
78 height : '0.1rem' ,
89 } ,
Original file line number Diff line number Diff line change 11import * as React from 'react'
22import { css , jsx } from '@emotion/core'
3+ import { useWindowResize } from '../../services/hooks/resize'
34
45interface Props {
56 children : React . ReactElement
67}
78
8- const resize = ( ) => ( {
9- width : window . innerWidth ,
10- height : window . innerHeight ,
11- } )
9+ const styles = {
10+ page : {
11+ display : 'flex' as 'flex' ,
12+ position : 'relative' as 'relative' ,
13+ margin : 0 ,
14+ backgroundColor : 'white' ,
15+ } ,
16+ }
1217
1318const Workspace = ( { children } : Props ) => {
14- const [ dimensions , setDimensions ] = React . useState ( resize ( ) )
15-
16- // solution for windows getting off size
17- React . useEffect ( ( ) => {
18- setDimensions ( resize ( ) )
19- } , [ window . innerHeight , window . innerWidth ] )
20-
21- const styles = {
22- page : {
23- display : 'flex' as 'flex' ,
24- position : 'relative' as 'relative' ,
25- margin : 0 ,
26- backgroundColor : 'white' ,
27- } ,
28- }
29-
19+ const dimensions = useWindowResize ( )
3020 return < div css = { { ...styles . page , ...dimensions } } > { children } </ div >
3121}
3222
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+
3+ export const useWindowResize = ( ) => {
4+ const resize = ( ) => ( {
5+ width : window . innerWidth ,
6+ height : window . innerHeight ,
7+ } )
8+
9+ const [ dimensions , setDimensions ] = React . useState ( resize ( ) )
10+
11+ // solution for windows getting off size
12+ React . useEffect ( ( ) => {
13+ const handleResize = ( ) => {
14+ setDimensions ( resize ( ) )
15+ }
16+ window . addEventListener ( 'resize' , handleResize )
17+ return ( ) => window . removeEventListener ( 'resize' , handleResize )
18+ } , [ ] )
19+ return dimensions
20+ }
You can’t perform that action at this time.
0 commit comments