Created
June 7, 2023 14:20
-
-
Save somidad/603eeb9829e591f7e57bf88931100947 to your computer and use it in GitHub Desktop.
Read a file on React
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
function Component() { | |
const onChange = (e) => { | |
const file = e.target.files?.[0]; | |
if (!file) { | |
return; | |
} | |
const reader = new FileReader(); | |
reader.addEventListener('load', () => { | |
console.log(reader.result); | |
}); | |
reader.readAsText(file); | |
} | |
return ( | |
<div> | |
<input type='file' onChange={onChange} /> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment