File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ export const MediaConsumer = ({
1919 sizes
2020} : IProps ) => {
2121 const currentSize = useMedia ( sizes ) ;
22+
23+ if ( ! currentSize ) {
24+ return null ;
25+ }
2226 return children ( currentSize ) ;
2327} ;
2428
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ const useMedia = (sizes?: NoXsMediaSize[]) => {
1313 const breakpoints = theme [ themeName ] ?. gridBreakpoints ;
1414
1515 const getResize = ( ) => {
16- const width = typeof window !== 'undefined' ? window . innerWidth : 0 ;
16+ if ( typeof window === 'undefined' ) {
17+ return null ;
18+ }
19+ const width = window . innerWidth ;
1720 let size : TMediaSize = 'xs' ;
1821
1922 if ( ( ! sizes || sizes ?. includes ( 'xxl' ) ) && width >= breakpoints . xxl ) {
@@ -31,7 +34,7 @@ const useMedia = (sizes?: NoXsMediaSize[]) => {
3134 return size ;
3235 } ;
3336
34- const [ currentSize , setCurrentSize ] = useState < TMediaSize > ( getResize ( ) ) ;
37+ const [ currentSize , setCurrentSize ] = useState < TMediaSize | null > ( getResize ( ) ) ;
3538
3639 useEffect ( ( ) => {
3740 const handleResize = ( ) => {
You can’t perform that action at this time.
0 commit comments