Skip to content

Commit

Permalink
add breakpoints to hook
Browse files Browse the repository at this point in the history
relates #69
  • Loading branch information
arrested-developer committed Oct 4, 2019
1 parent fd5811e commit 03ac217
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/useWindowWidth.js → src/hooks/useWindowWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useState, useEffect } from 'react';

// constants
import { sizeNum } from './constants/breakpoints';
import { sizeNum } from '../constants/breakpoints';

const useWindowWidth = () => {
const isClient = typeof window === 'object';
Expand All @@ -23,8 +23,27 @@ const useWindowWidth = () => {
return () => window.removeEventListener('resize', handleResize);
}, [isClient]);

const { tablet } = sizeNum;
return { isTablet: windowWidth < tablet };
const {
mobileS,
mobileM,
mobileL,
mobileXL,
tablet,
laptop,
laptopL,
desktop,
} = sizeNum;

return {
isMobileS: windowWidth < mobileS,
isMobileM: windowWidth < mobileM,
isMobileL: windowWidth < mobileL,
isMobileXL: windowWidth < mobileXL,
isTablet: windowWidth < tablet,
isLaptop: windowWidth < laptop,
isLaptopL: windowWidth < laptopL,
isDesktop: windowWidth < desktop,
};
};

export default useWindowWidth;

0 comments on commit 03ac217

Please sign in to comment.