diff --git a/src/components/DeviceNode.tsx b/src/components/DeviceNode.tsx index a0b6f76..e2bbd82 100644 --- a/src/components/DeviceNode.tsx +++ b/src/components/DeviceNode.tsx @@ -43,11 +43,14 @@ const DeviceNode: React.FC = ({ } }, []); - const snapToGrid = (x: number, y: number) => { - const snappedX = Math.round(x / device.gridSize) * device.gridSize; - const snappedY = Math.round(y / device.gridSize) * device.gridSize; - return { x: snappedX, y: snappedY }; - }; + const snapToGrid = React.useCallback( + (x: number, y: number) => { + const snappedX = Math.round(x / device.gridSize) * device.gridSize; + const snappedY = Math.round(y / device.gridSize) * device.gridSize; + return { x: snappedX, y: snappedY }; + }, + [device.gridSize] + ); useEffect(() => { const handleMouseMove = (e: MouseEvent) => { @@ -83,7 +86,7 @@ const DeviceNode: React.FC = ({ window.removeEventListener("mousemove", handleMouseMove); window.removeEventListener("mouseup", handleMouseUp); }; - }, [isDragging, device.id, onMove, position, device.gridSize]); + }, [isDragging, device.id, onMove, position, snapToGrid]); const handleMouseDown = (e: React.MouseEvent) => { e.preventDefault();