【发布时间】:2016-05-07 16:56:42
【问题描述】:
假设我有未指定数量的图像正在使用 Andrew Farmer's example image component,它会检测每个单独图像的加载时间:
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;
使用 Flux 或 Redux 之类的框架,同步所有图像组件以检测所有图像何时完成加载的最简单方法是什么?
【问题讨论】:
标签: javascript reactjs flux redux