Skip to content

Commit

Permalink
feat(project): add use breakpoint hook
Browse files Browse the repository at this point in the history
  • Loading branch information
demmyhonore committed Apr 29, 2021
1 parent 303a5e8 commit 24fdf83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/hooks/useBreakpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState, useEffect } from 'react';
import throttle from 'lodash.throttle';

const getDeviceConfig = (width: number) => {
if (width < 320) {
return 'xs';
} else if (width >= 320 && width < 720) {
return 'sm';
} else if (width >= 720 && width < 1024) {
return 'md';
} else if (width >= 1024) {
return 'lg';
}
};

const useBreakpoint = () => {
const [breakPoint, setBreakpoint] = useState(() => getDeviceConfig(window.innerWidth));

useEffect(() => {
const calcInnerWidth = throttle(function () {
setBreakpoint(getDeviceConfig(window.innerWidth))
}, 200);
window.addEventListener('resize', calcInnerWidth);
return () => window.removeEventListener('resize', calcInnerWidth);
}, []);

return breakPoint;
}
export default useBreakpoint;
2 changes: 1 addition & 1 deletion src/screens/Playlist/Playlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styles from './Playlist.module.scss';
function Playlist() {
return (
<div className={styles.playlist}>
<PlaylistContainer playlistId="sR5VypYk" />
<PlaylistContainer playlistId="sR5VypYk" /* temp data, till config arrives */ />
</div>
);
}
Expand Down

0 comments on commit 24fdf83

Please sign in to comment.