/result.jsx Secret
Created
November 14, 2021 09:28
final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
function MyPage() { | |
const [imageSrc, setImageSrc] = useState(''); | |
const encodeFileToBase64 = (fileBlob) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(fileBlob); | |
return new Promise((resolve) => { | |
reader.onload = () => { | |
setImageSrc(reader.result); | |
resolve(); | |
}; | |
}); | |
}; | |
return ( | |
<main className="container"> | |
<h2>이미지 미리보기</h2> | |
<input type="file" onChange={(e) => { | |
encodeFileToBase64(e.target.files[0]); | |
}} /> | |
<div className="preview"> | |
{imageSrc && <img src={imageSrc} alt="preview-img" />} | |
</div> | |
</main> | |
); | |
} | |
export default MyPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment