From d2ceb5007e1f1ee20f2623064a0b2ea8fbeb4b32 Mon Sep 17 00:00:00 2001 From: Pkpedram Date: Wed, 6 Apr 2022 14:45:04 +0430 Subject: [PATCH] Deleting Image Done --- src/view/addProduct/components/addPic.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/view/addProduct/components/addPic.js b/src/view/addProduct/components/addPic.js index e5227c8..2e049b0 100644 --- a/src/view/addProduct/components/addPic.js +++ b/src/view/addProduct/components/addPic.js @@ -6,6 +6,7 @@ const AddPic = () => { const [selectedImage, setSelectedImage] = useState(null); const [fakeState, setFakeState] = useState(5); const [deleteFirst, setDeleteFirst] = useState(false) + const [deleteImage, setDeleteImage] = useState(null); useEffect(() => { if (selectedImage) { @@ -42,7 +43,19 @@ const AddPic = () => {
{ imageUrl.slice(1,imageUrl.length).map((item, index) => ( +
{setDeleteImage(index); console.log(index)}} + onMouseLeave={() => setDeleteImage(null)} + > + { + deleteImage == index &&
+ { + let newImageArray = imageUrl.filter((itm, idx) => idx !== index + 1); + setImageUrl(newImageArray) + }}/> +
+ } +
)) }