I am trying to copy and paste within my div using Keybord. It was triggering twice and I founc the following code triggering twice. How can I solve it?
useEffect(() => {
const handleKeyDown = (e) => {
e.preventDefault();
if ((e.ctrlKey || e.metaKey) && e.key === "c") {
if (selectedRowIndex !== null && explorerContent[selectedRowIndex]) {
handleCopy(explorerContent[selectedRowIndex]);
} else {
console.warn("No item selected to copy.");
}
}
if ((e.ctrlKey || e.metaKey) && e.key === "v") {
handlePasteWithConflictResolution();
}
};
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [selectedRowIndex, explorerContent, currentPath, clipboard]);
No item selected to copy.
is showing twice here
2