Created
January 24, 2018 06:23
-
-
Save huozhi/4d2cfb09ad54c3a39d4f941c2947e20a to your computer and use it in GitHub Desktop.
read content when drop file with drag events
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
const readOnDrop = (element, onRead) => { | |
element.addEventListener('dragover', ev => ev.preventDefault()) | |
element.addEventListener('drop', ev => { | |
ev.preventDefault() | |
const dt = ev.dataTransfer | |
const file = dt.files[0] | |
const reader = new FileReader() | |
reader.onload = event => onRead(event.target.result) | |
reader.readAsText(file) | |
}) | |
} | |
export default readOnDrop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment