반응형
function Home() {
const [attachment, setAttachment] = useState();
const handleAddPhoto = (event) => {
console.log("handleAddPhoto");
const {
target: { files },
} = event;
const theFile = files[0];
const reader = new FileReader();
reader.onloadend = (finishedEvent) => {
const {
currentTarget: { result },
} = finishedEvent;
setAttachment(result);
};
reader.readAsDataURL(theFile);
};
return (
<div>
{attachment && (
<div>
<img src={attachment} width="200px" height="200px" />
</div>
)}
<input
type="file"
name="imageFile"
accept="image/*"
onChange={handleAddPhoto}
/>
</div>
);
}
반응형
'[====== Development ======] > React' 카테고리의 다른 글
[VSCode] JavaScript (ES6) code snippets (0) | 2022.08.09 |
---|---|
uuid값 생성하기 (0) | 2022.03.16 |
[React Study] Link Page (0) | 2022.01.16 |
Rounded Input textbox (0) | 2022.01.11 |
[React Study] Movie List (0) | 2022.01.11 |