Last active
April 16, 2019 15:28
-
-
Save Olegas/30006f696412908ae68ba88c37254de1 to your computer and use it in GitHub Desktop.
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 [images, setImages] = useState([]); | |
| function loadFileAsync(file) { | |
| const reader = new FileReader(); | |
| return new Promise((resolve, reject) => { | |
| reader.onloadend = (e) => { | |
| resolve(e.target.result); | |
| }; | |
| // TODO handle error | |
| reader.readAsDataURL(file); | |
| }); | |
| } | |
| function handleChanges(e) { | |
| const {files} = e; | |
| if (files.length) { | |
| Promise.all(files.map((file) => loadFileAsync(file))).then((images) => setImages(images)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment