]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/ui/components/image_loader.js
1 import React
from 'react';
2 import PropTypes
from 'prop-types';
4 class ImageLoader
extends React
.PureComponent
{
7 src: PropTypes
.string
.isRequired
,
15 componentWillMount() {
16 this.loadImage(this.props
.src
);
19 componentWillReceiveProps(props
) {
20 this.loadImage(props
.src
);
24 const image
= new Image();
25 image
.onerror
= () => this.setState({ loading: false, error: true });
26 image
.onload
= () => this.setState({ loading: false, error: false });
29 this.setState({ loading: true });
33 const { src
} = this.props
;
34 const { loading
, error
} = this.state
;
36 // TODO: handle image error state
38 const imageClass
= `image-loader__img ${loading ? 'image-loader__img-loading' : ''}`;
40 return <img className
={imageClass
} src
={src
} />; // eslint
-disable
-line jsx
-a11y
/img
-has
-alt
45 export default ImageLoader
;
This page took 0.097549 seconds and 5 git commands to generate.