Skip to content

Commit

Permalink
Fix window size loading
Browse files Browse the repository at this point in the history
  • Loading branch information
low-earth-orbit committed Aug 25, 2024
1 parent eda0345 commit f79a274
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 1 addition & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import Canvas from "@/components/Canvas";
import { MantineProvider } from "@mantine/core";

export default function Home() {
return (
<MantineProvider>
<Canvas />
</MantineProvider>
);
return <Canvas />;
}
18 changes: 12 additions & 6 deletions components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export default function Canvas() {
const [tool, setTool] = useState<string>("pen");
const [lines, setLines] = useState<LineType[]>([]);
const isDrawing = useRef<boolean>(false);
const [stageSize, setStageSize] = useState<{ width: number; height: number }>(
{
width: 0,
height: 0,
}
);
const [stageSize, setStageSize] = useState<{
width: number;
height: number;
}>();

const handleMouseDown = (e: any) => {
isDrawing.current = true;
Expand Down Expand Up @@ -54,12 +52,20 @@ export default function Canvas() {
});
};

// Update the size on mount
handleResize();

window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);

// component has not finished loading the window size
if (!stageSize) {
return null;
}

return (
<div>
<Stage
Expand Down

0 comments on commit f79a274

Please sign in to comment.