prevent error occurering due to zoom in -out

This commit is contained in:
pramod.mahajan 2025-10-25 11:02:57 +05:30
parent d7caf47498
commit 4238157fd4

View File

@ -1,4 +1,4 @@
import { useState, useRef } from "react"; import { useState, useRef ,useEffect} from "react";
const PreviewDocument = ({ imageUrl }) => { const PreviewDocument = ({ imageUrl }) => {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
@ -20,6 +20,16 @@ const PreviewDocument = ({ imageUrl }) => {
setZoom((prev) => Math.min(Math.max(prev + delta, 0.5), 3)); setZoom((prev) => Math.min(Math.max(prev + delta, 0.5), 3));
}; };
useEffect(() => {
const container = containerRef.current;
if (!container) return;
container.addEventListener("wheel", handleWheel, { passive: false });
return () => {
container.removeEventListener("wheel", handleWheel);
};
}, []);
const handleMouseDown = (e) => { const handleMouseDown = (e) => {
if (zoom <= 1) return; if (zoom <= 1) return;
setIsDragging(true); setIsDragging(true);
@ -73,7 +83,6 @@ const PreviewDocument = ({ imageUrl }) => {
<div <div
ref={containerRef} ref={containerRef}
onWheel={handleWheel}
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove} onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp} onMouseUp={handleMouseUp}