diff --git a/src/components/Board/Board.tsx b/src/components/Board/Board.tsx index 4c93019..24fe097 100644 --- a/src/components/Board/Board.tsx +++ b/src/components/Board/Board.tsx @@ -226,44 +226,47 @@ const Board = React.forwardRef( }, points[0]); }; - const addCornerObjectToPolygon = ( - polygon: fabric.Object, - index: number, - scaledCoords: { - x: number; - y: number; - }[], - size?: number, - ) => { - if (!editor?.canvas) return; - - const cornerObject = new CustomCornerObject({ - number: index + 1, - size, - }); + const addCornerObjectToPolygon = useCallback( + ( + polygon: fabric.Object, + index: number, + scaledCoords: { + x: number; + y: number; + }[], + size?: number, + ) => { + if (!editor?.canvas) return; + + const cornerObject = new CustomCornerObject({ + number: index + 1, + size, + }); - cornerObject.set({ - left: findBottomRight(scaledCoords).x, - top: findBottomRight(scaledCoords).y, - }); + cornerObject.set({ + left: findBottomRight(scaledCoords).x, + top: findBottomRight(scaledCoords).y, + }); - editor.canvas.add(cornerObject); + editor.canvas.add(cornerObject); - // Ensure the corner object moves with the polygon - polygon.on("moving", () => { - const newBounds = polygon.getBoundingRect(); - cornerObject.set({ - left: newBounds.left + newBounds.width, - top: newBounds.top + newBounds.height, + // Ensure the corner object moves with the polygon + polygon.on("moving", () => { + const newBounds = polygon.getBoundingRect(); + cornerObject.set({ + left: newBounds.left + newBounds.width, + top: newBounds.top + newBounds.height, + }); + editor.canvas.renderAll(); }); - editor.canvas.renderAll(); - }); - // Ensure the corner object is removed when the polygon is removed - polygon.on("removed", () => { - editor.canvas?.remove(cornerObject); - }); - }; + // Ensure the corner object is removed when the polygon is removed + polygon.on("removed", () => { + editor.canvas?.remove(cornerObject); + }); + }, + [editor?.canvas], + ); useEffect(() => { const parentCanvasElement = document.getElementById(