2
比方说,我有使用Andrew Farmer's example image component当每个个体图像加载检测图像的数目不详:同步多个图像的onLoad与之反应
import React from 'react';
class ImageWithStatusText extends React.Component {
constructor(props) {
super(props);
this.state = { imageStatus: null };
}
handleImageLoaded() {
this.setState({ imageStatus: 'loaded' });
}
handleImageErrored() {
this.setState({ imageStatus: 'failed to load' });
}
render() {
return (
<div>
<img
src={this.props.imageUrl}
onLoad={this.handleImageLoaded.bind(this)}
onError={this.handleImageErrored.bind(this)}
/>
{this.state.imageStatus}
</div>
);
}
}
export default ImageWithStatusText;
使用诸如焊剂或终极版的框架,有什么最简单的方法来同步所有图像组件,以检测何时加载完所有图像?