Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Created June 13, 2021 15:44
Show Gist options
  • Save DZuz14/d0b545e3a170224fcbd6a08bdfe48bfd to your computer and use it in GitHub Desktop.
Save DZuz14/d0b545e3a170224fcbd6a08bdfe48bfd to your computer and use it in GitHub Desktop.
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