mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 08:07:40 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
31
apps/web-react/app/hooks/useWindowSize.ts
Normal file
31
apps/web-react/app/hooks/useWindowSize.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as React from "react";
|
||||
|
||||
interface WindowSize {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void) {
|
||||
window.addEventListener("resize", listener);
|
||||
return () => window.removeEventListener("resize", listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current window dimensions, re-rendering on resize. Both
|
||||
* dimensions are `0` during server-side rendering and the initial hydration
|
||||
* render.
|
||||
*/
|
||||
export function useWindowSize(): WindowSize {
|
||||
const width = React.useSyncExternalStore(
|
||||
subscribe,
|
||||
() => window.innerWidth,
|
||||
() => 0,
|
||||
);
|
||||
const height = React.useSyncExternalStore(
|
||||
subscribe,
|
||||
() => window.innerHeight,
|
||||
() => 0,
|
||||
);
|
||||
|
||||
return { width, height };
|
||||
}
|
||||
Reference in New Issue
Block a user