solved warning

This commit is contained in:
smfahim25 2025-02-02 16:38:02 +06:00
parent 1cf062f326
commit 2c4835c04a

View file

@ -1,4 +1,4 @@
import { useEffect, useContext, useState, useRef } from "react";
import { useEffect, useContext, useState, useRef, useCallback } from "react";
import { AspectRatio } from "@/components/ui/aspect-ratio";
import OpenContext from "../Context/openContext/OpenContext";
import CanvasContext from "../Context/canvasContext/CanvasContext";
@ -30,25 +30,28 @@ export default function Canvas() {
const [zoomLevel, setZoomLevel] = useState(100);
const containerRef = useRef(null);
const handleZoom = (newZoom) => {
const zoom = Math.min(Math.max(newZoom, 0), 100);
setZoomLevel(zoom);
const handleZoom = useCallback(
(newZoom) => {
const zoom = Math.min(Math.max(newZoom, 0), 100);
setZoomLevel(zoom);
if (canvasRef.current && canvas) {
const scale = zoom / 100;
if (canvasRef.current && canvas) {
const scale = zoom / 100;
// Update canvas dimensions
const newWidth = canvasRef.current.offsetWidth * scale;
const newHeight = canvasRef.current.offsetHeight * scale;
// Update canvas dimensions
const newWidth = canvasRef.current.offsetWidth * scale;
const newHeight = canvasRef.current.offsetHeight * scale;
canvas.setWidth(newWidth);
canvas.setHeight(newHeight);
setCanvasWidth(newWidth);
setCanvasHeight(newHeight);
canvas.setWidth(newWidth);
canvas.setHeight(newHeight);
setCanvasWidth(newWidth);
setCanvasHeight(newHeight);
canvas.renderAll();
}
};
canvas.renderAll();
}
},
[canvas, canvasRef, setCanvasHeight, setCanvasWidth]
);
useEffect(() => {
if (!canvas) return;
@ -154,7 +157,7 @@ export default function Canvas() {
window.removeEventListener("resize", handleResize);
}
};
}, [canvas, setActiveObject, zoomLevel]);
}, [canvas, setActiveObject, zoomLevel, handleZoom]);
useEffect(() => {
import("fabric").then((fabricModule) => {