Skip to content

Instantly share code, notes, and snippets.

@hunzo
Last active October 13, 2021 03:51
Show Gist options
  • Save hunzo/72910e784b5a29c65c223e931c7ad296 to your computer and use it in GitHub Desktop.
Save hunzo/72910e784b5a29c65c223e931c7ad296 to your computer and use it in GitHub Desktop.
import React from 'react'
import './App.css'
function App() {
const handleFile = (e: React.ChangeEvent<HTMLInputElement>) => {
// if (!e.target.files) return // solv #1 remove null FileList | null
const files = e.target.files! // solv #2 it will not be null, trust me". haha
Array.from(files).forEach(async (f) => console.log(f))
}
return (
<div className="App">
<input
multiple
type="file"
name="file"
id="file-upload"
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleFile(e)
}
/>
<button>submit</button>
</div>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment