mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-10-23 00:19:23 +08:00
feat: chat panel redesigned ui
This commit is contained in:
36
app/hooks/useWindowSize.ts
Normal file
36
app/hooks/useWindowSize.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useLayoutEffect, useMemo, useRef } from "react";
|
||||
|
||||
type Size = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
export function useWindowSize(callback: (size: Size) => void) {
|
||||
const callbackRef = useRef<typeof callback>();
|
||||
const hascalled = useRef(false);
|
||||
|
||||
if (typeof window !== "undefined" && !hascalled.current) {
|
||||
callback({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
hascalled.current = true;
|
||||
}
|
||||
|
||||
callbackRef.current = callback;
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const onResize = () => {
|
||||
callbackRef.current?.({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener("resize", onResize);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("resize", onResize);
|
||||
};
|
||||
}, []);
|
||||
}
|
Reference in New Issue
Block a user