Skip to content

Instantly share code, notes, and snippets.

@ilonacodes
Created April 20, 2020 11:24
Show Gist options
  • Save ilonacodes/5159f439c801004ff6505179756fac9f to your computer and use it in GitHub Desktop.
Save ilonacodes/5159f439c801004ff6505179756fac9f to your computer and use it in GitHub Desktop.
const ImportFromFileBodyComponent = () => {
let fileReader;
const handleFileRead = (e) => {
const content = fileReader.result;
console.log(content)
// … do something with the 'content' …
};
const handleFileChosen = (file) => {
fileReader = new FileReader();
fileReader.onloadend = handleFileRead;
fileReader.readAsText(file);
};
return <div className='upload-expense'>
<input
type='file'
id='file'
className='input-file'
accept='.csv'
onChange={e => handleFileChosen(e.target.files[0])}
/>
</div>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment