forked from rajeshpillai/youtube-react-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlide.js
More file actions
50 lines (41 loc) · 1.01 KB
/
Slide.js
File metadata and controls
50 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
export default class Slide extends React.Component {
state = {
isLoaded: false,
isError: false
}
componentDidMount() {
this.load(this.img);
}
load(img) {
var image = img;
if (image === null) return;
image.src = this.props.url;
image.onload = () => {
this.onImageLoaded();
}
image.onerror = () => {
this.onImageLoadError(this.props.url);
}
}
onImageLoaded = () => {
this.setState({
isLoaded: true
});
}
onImageLoadError = () => {
this.setState({
isError: true
})
}
render () {
let url = this.props.url;
if (this.state.isError) return null;
return (
<div className="slide">
{!this.state.isLoaded && <img src="./images/loading.svg" alt="loading" />}
<img ref={(img)=> this.img = img} />
</div>
);
}
}