Created
November 25, 2020 15:38
-
-
Save krutoo/a399e265f176be72f0590d55957c846d to your computer and use it in GitHub Desktop.
Simplest async image loading
This file contains 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
export const loadImage = path => new Promise((resolve, reject) => { | |
const image = new Image(); | |
image.onload = () => resolve(image); | |
image.onerror = () => reject(image); | |
image.src = path; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment