ChatGPT-Next-Web/app/store/screen.ts
Jun Wu 4e0eef4398 fix: re-render if isMobileScreen() changes
Before this change, even with "tight border" enabled, resizing the window from
mobile to non-mobile does not use tight border.

After this change, the "tight border" config is respected as expected.
2023-04-05 23:48:04 -07:00

21 lines
440 B
TypeScript

import { create } from "zustand";
import { isMobileScreen } from "../utils";
interface Screen {
isMobile: boolean;
update: () => void;
}
export const useScreen = create<Screen>(set => {
const state = {
isMobile: isMobileScreen(),
update: () => set({ isMobile: isMobileScreen() }),
};
if (typeof window !== "undefined") {
window.addEventListener("resize", e => {
state.update();
});
}
return state;
});