Skip to content

Instantly share code, notes, and snippets.

@ilonacodes
Created April 20, 2020 11:24

Revisions

  1. ilonacodes created this gist Apr 20, 2020.
    25 changes: 25 additions & 0 deletions index.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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>;
    };