Skip to content

Commit

Permalink
Merge pull request #53 from heyjul3s/refactor/usematchmedia-usewindow…
Browse files Browse the repository at this point in the history
…size

Hooks Update
  • Loading branch information
heyjul3s committed Jan 26, 2021
2 parents 5dbefae + 222fc3c commit 40bdcf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/usematchmedia/src/useMatchMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export function useMatchMedia(query: string): boolean {
}, []);

useEffect(() => {
matchListRef.current = window.matchMedia(query);
matchListRef.current.addEventListener('change', onMediaQueryListEvent);
setIsMatch(matchListRef.current.matches);
if (!!window) {
matchListRef.current = window.matchMedia(query);
matchListRef.current.addEventListener('change', onMediaQueryListEvent);
setIsMatch(matchListRef.current.matches);
} else {
console.error('Error: typeof "window" is undefined.');
setIsMatch(false);
}

return function unmountUseMatchMedia() {
if (matchListRef.current) {
Expand Down
2 changes: 1 addition & 1 deletion packages/usewindowsize/src/useWindowSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function useWindowSize(): WindowSize {
const [windowSize, setWindowSize] = useState<WindowSize>(getSize());

function getSize() {
if (typeof window !== 'undefined') {
if (!!window) {
return {
innerHeight: window.innerHeight,
innerWidth: window.innerWidth,
Expand Down

0 comments on commit 40bdcf2

Please sign in to comment.