Files
frontend-app-learning/src/generic/tabs/useWindowSize.js
David Joy 73c74119f0 Organizationing (#102)
* Moving model-store into “generic” sub-directory.

Also adding a README.md to explain what belongs in “generic”

* Moving user-messages into “generic” sub-directory.

* Moving PageLoading into “generic” sub-directory.

* Moving “tabs” module into “generic” sub-directory.

* Moving InstructorToolbar and MasqueradeWidget up to instructor-toolbar.

The masquerade widget is a sub-module of instructor-toolbar.

* Co-locating celebration APIs with celebration utils.

Also adding an ADR about thunk/API naming conventions and making some other areas of the code adhere to it.

* Moving courseware data (thunks, api) into the courseware module.

Note that cousre-home/data/api still uses normalizeBlocks - this should be fixed so it’s not reaching across.  Maybe we pull that particular API up top.

This PR includes a few TODOs for things I saw, as well as a tiny bit of whitespace cleanup.
2020-07-02 13:11:50 -04:00

27 lines
632 B
JavaScript

import { useState, useEffect } from 'react';
export default function useWindowSize() {
const isClient = typeof global === 'object';
const getSize = () => ({
width: isClient ? global.innerWidth : undefined,
height: isClient ? global.innerHeight : undefined,
});
const [windowSize, setWindowSize] = useState(getSize);
useEffect(() => {
if (!isClient) {
return false;
}
const handleResize = () => {
setWindowSize(getSize());
};
global.addEventListener('resize', handleResize);
return () => global.removeEventListener('resize', handleResize);
}, []);
return windowSize;
}