From d70b820b62f54e2d301ba277b3b887385e88e1fc Mon Sep 17 00:00:00 2001 From: jaeyo03 Date: Sat, 9 Nov 2024 01:44:51 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix=20:=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EC=8B=9C=20=EC=9E=AC=EB=9E=9C=EB=8D=94?= =?UTF-8?q?=EB=A7=81=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20blob=20=EC=83=9D=EC=84=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WriteReview/UploadImageSection.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/WriteReview/UploadImageSection.tsx b/src/components/WriteReview/UploadImageSection.tsx index 20cbc0b..62ebdba 100644 --- a/src/components/WriteReview/UploadImageSection.tsx +++ b/src/components/WriteReview/UploadImageSection.tsx @@ -2,6 +2,7 @@ import tw from "twin.macro"; import styled from "styled-components"; import CameraSvg from "../../assets/images/camera.svg?react"; import { MdDeleteOutline } from "react-icons/md"; +import {useEffect, useMemo} from "react"; type UploadImageProps = { imageFiles: File[]; setImageFiles: React.Dispatch>; @@ -14,6 +15,8 @@ function UploadImageSection({ imageFiles, setImageFiles }: UploadImageProps) { const newFiles = [...prevFiles, ...filesArray]; return newFiles; }); + // 파일 선택 후 input의 값을 초기화하여 동일 파일 업로드 가능하게 만듦 + event.target.value = ""; } }; const handleImageDelete = (index: number) => { @@ -21,7 +24,19 @@ function UploadImageSection({ imageFiles, setImageFiles }: UploadImageProps) { const updatedFiles = imageFiles.filter((_, i) => i !== index); setImageFiles(updatedFiles); }; - + + // imageFiles가 변경될 때만 URL 생성 + const imageUrls = useMemo(() => { + return imageFiles.map((file) => URL.createObjectURL(file)); + }, [imageFiles]); + + // Blob URL 해제 + useEffect(() => { + return () => { + imageUrls.forEach((url) => URL.revokeObjectURL(url)); + }; + }, [imageUrls]); + return ( + ); + } + return (
@@ -22,8 +39,7 @@ function CheckPhoto() {
- - QR 사진 + 업로드 사진
);