Created
June 13, 2021 15:44
-
-
Save DZuz14/d0b545e3a170224fcbd6a08bdfe48bfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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, useEffect } from 'react'; | |
export const useFileUpload = () => { | |
const [files, setFilesState] = useState([]) | |
const setFiles = e => { | |
let filesArr = [] | |
if (e.currentTarget?.files) { | |
filesArr = Array.from(e.currentTarget.files); | |
} else if (e?.dataTransfer.files) { | |
filesArr = Array.from(e.dataTransfer.files); | |
} | |
setFilesState(filesArr) | |
} | |
return { | |
files, | |
setFiles | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment