My goal is to have my gallery images render in as they load.
Looking online, I have learned about the onLoad method.
This is what I have tried to utilise, the idea being that the preloader.gif would render until the image is loaded and simply replace the image src with the loaded image.
As it is now(below), the images seem to load in the same way they normally would if I didn't use the onLoad method so there is a moment where no image is being rendered at all before the images load in.
What am I doing wrong exactly?
I've stripped down the code to make the question easier to read.
import React from 'react';
import ReactDOM from 'react-dom';
import preloaderImage from '../../../img/site/preloader.gif';
class WorksPage extends React.Component {
constructor(){
super();
}
imageLoadHandler(image,e) {
e.target.src = image;
}
render() {
const listWork = this.props.array.map((item,index)=> {
return(
<li key={item.id}>
<div>
<img src={preloaderImage} onLoad={this.imageLoadHandler.bind(this,item.image)}/>
</div>
</li>
)
});
return(
<li>
<div>
<ul>
{listWork}
</ul>
</div>
</li>
)
}
}
module.exports = WorksPage;
remove the e.target.src = imagecode thepreloaderimage loads.