Answers for "how to upload image and preview in react"

1

display preview of image upload react

<!-- html + Javascript -->

//js
<script>
  const handleChange = (e) =>{
     const file = URL.createObjectURL(e.target.files[0])
     document.getElementById("preview-img").src = file;
  }
  document.getElementById("file-input").addEventListener("change", handleChange);
</script>
     

 //html
 <div>
  <input id="file-input" type="file"/>
  <img id="preview-img" src="" width="200"/>
</div>
Posted by: Guest on August-06-2021

Code answers related to "how to upload image and preview in react"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language