Created
April 12, 2020 21:01
-
-
Save diogomoretti/a419dea9dfd1f69f1e32827cb182e973 to your computer and use it in GitHub Desktop.
useUpload – Simple upload hook for React applications
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' | |
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