Skip to content

Instantly share code, notes, and snippets.

@diogomoretti
Created April 12, 2020 21:01
Show Gist options
  • Save diogomoretti/a419dea9dfd1f69f1e32827cb182e973 to your computer and use it in GitHub Desktop.
Save diogomoretti/a419dea9dfd1f69f1e32827cb182e973 to your computer and use it in GitHub Desktop.
useUpload – Simple upload hook for React applications
import { useState } from 'react'
export default function useUpload () {
const [file, setFile] = useState('')
const [fileName, setFileName] = useState('')
const onChangeHandler = e => {
setFile(e.target.files[0])
setFileName(e.target.files[0].name)
}
return { file, fileName, onChangeHandler }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment