JSFiddle - React, Tailwind, and code Playground

by cs09g

JavaScript

handleSubmit(e) {
  e.preventDefault()
  let uploadPhotoInput = document.getElementById("upload")

  if (uploadPhotoInput.files[0]) {
    let fileData = uploadPhotoInput.files[0]
    let formData = new FormData();
    formData.append('file', fileData)
    debugger
    this.props.uploadPhoto(formData)
  }
}

render() {
  return ( <
    div >
    <
    form onSubmit = {
      this.handleSubmit
    } >
    <
    input id = "upload"
    type = "file"
    accept = "image/png, image/jpeg" /
    >
    <
    input type = "submit"
    value = "Upload" /
    >
    <
    /form> < /
    div >
  )
}