diff --git a/src/Target/components/FavoriteImageInput/index.tsx b/src/Target/components/FavoriteImageInput/index.tsx index f2eb5352..a007a6ac 100644 --- a/src/Target/components/FavoriteImageInput/index.tsx +++ b/src/Target/components/FavoriteImageInput/index.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { IcCamera, ImgBook } from '../../../assets'; import * as S from './FavoriteImageInput.style'; @@ -11,6 +11,18 @@ function FavoriteImageInput({ changeFileData }: FavoriteImageInputProps) { const imgRef = useRef(null); const [imgFile, setImgFile] = useState(''); + useEffect(() => { + if ( + sessionStorage.getItem('image') && + sessionStorage.getItem('image') !== null + ) { + const a = sessionStorage.getItem('image'); + if (typeof a === 'string') { + setImgFile(a); + } + } + }, []); + const handleImageUpload = async (): Promise => { const fileInput = imgRef.current; @@ -21,6 +33,7 @@ function FavoriteImageInput({ changeFileData }: FavoriteImageInputProps) { base64Reader.readAsDataURL(file); base64Reader.onloadend = () => { if (base64Reader.result !== null) { + sessionStorage.setItem('image', base64Reader.result as string); changeFileData(file); setImgFile(base64Reader.result as string); } diff --git a/src/Target/page/TargetPage/index.tsx b/src/Target/page/TargetPage/index.tsx index 221311bf..36dd6657 100644 --- a/src/Target/page/TargetPage/index.tsx +++ b/src/Target/page/TargetPage/index.tsx @@ -24,6 +24,18 @@ function TargetPage() { const { data, isLoading } = useGetPresignedUrl(); const putMutation = usePutPresignedUrl(); + useEffect(() => { + if ( + sessionStorage.getItem('name') && + sessionStorage.getItem('name') !== null + ) { + const a = sessionStorage.getItem('name'); + if (typeof a === 'string') { + setName(a); + } + } + }, []); + useEffect(() => { if (data) { const { url, fileName } = data; @@ -71,7 +83,10 @@ function TargetPage() {