Skip to content

Commit

Permalink
Change arg shape for getWindowSize instead of useWindowSize
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarrow committed Sep 25, 2023
1 parent 0a09563 commit df7ffbf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/docusaurus-theme-common/src/hooks/useWindowSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const windowSizes = {

type WindowSize = keyof typeof windowSizes;

function getWindowSize(desktopThresholdWidth = 996): WindowSize {
function getWindowSize({
desktopThresholdWidth = 996,
}: {
desktopThresholdWidth?: number;
}): WindowSize {
if (!ExecutionEnvironment.canUseDOM) {
return windowSizes.ssr;
}
Expand All @@ -42,21 +46,17 @@ const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
* In development mode, this hook will still return `"ssr"` for one second, to
* catch potential layout shifts, similar to strict mode calling effects twice.
*/
export function useWindowSize({
desktopThresholdWidth = 996,
}: {
desktopThresholdWidth?: number;
}): WindowSize {
export function useWindowSize(desktopThresholdWidth = 996): WindowSize {
const [windowSize, setWindowSize] = useState<WindowSize>(() => {
if (DevSimulateSSR) {
return 'ssr';
}
return getWindowSize(desktopThresholdWidth);
return getWindowSize({desktopThresholdWidth});
});

useEffect(() => {
function updateWindowSize() {
setWindowSize(getWindowSize(desktopThresholdWidth));
setWindowSize(getWindowSize({desktopThresholdWidth}));
}

const timeout = DevSimulateSSR
Expand Down

0 comments on commit df7ffbf

Please sign in to comment.