Skip to content

Instantly share code, notes, and snippets.

@biyootiful
Created December 2, 2017 07:53
Show Gist options
  • Save biyootiful/4f41e097d5a711f3500839b592a04d1c to your computer and use it in GitHub Desktop.
Save biyootiful/4f41e097d5a711f3500839b592a04d1c to your computer and use it in GitHub Desktop.
componentWillMount(){
this.preloadImg();
}
...
preloadImg(){
const imgURLs = imageURLsFromData;
for(let i = 0; i<imgURLs.length; i++){
let downloadingImg = new Image();
downloadingImg.src = imgURLs[i];
downloadingImg.onload = () =>{
imgLoadCount++;
if(imgLoadCount === imgURLs.length){
//initially set to "in progress"
this.setState({loading:"done"});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment