1
2class App extends React.Component {
3 constructor(){
4 super();
5 this.state = {loaded: false};
6 }
7
8 render(){
9 return (
10 <div>
11 {this.state.loaded ? null :
12 <div
13 style={{
14 background: 'red',
15 height: '400px',
16 width: '400px',
17 }}
18 />
19 }
20 <img
21 style={this.state.loaded ? {} : {display: 'none'}}
22 src={this.props.src}
23 onLoad={() => this.setState({loaded: true})}
24 />
25 </div>
26 );
27 }
28}
29
30ReactDOM.render(<App src={`http://placehold.it/400x400`} />, document.getElementById('root'));
31