-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3271 from SailingSteve/steveWebAppFeb13-4pm
Back ported LazyImage.jsx from Campaign
- Loading branch information
Showing
7 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
export default class LazyImage extends React.Component { | ||
constructor (props) { | ||
super(props); | ||
this.state = { | ||
src: null, | ||
}; | ||
} | ||
|
||
componentDidMount () { | ||
const { src } = this.props; | ||
console.log('LazyImage componentDidMount props:', this.props); | ||
|
||
const imageLoader = new Image(); | ||
imageLoader.src = src; | ||
|
||
imageLoader.onload = () => { | ||
console.log('LazyImage loaded src:', src); | ||
this.setState({ src }); | ||
}; | ||
} | ||
|
||
render () { | ||
const { placeholder, className, height, width, alt } = this.props; | ||
const { src } = this.state; | ||
return ( | ||
<img src={src || placeholder} className={className} height={height} width={width} alt={alt} /> | ||
); | ||
} | ||
} | ||
|
||
LazyImage.propTypes = { | ||
src: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
className: PropTypes.string, | ||
height: PropTypes.number, | ||
width: PropTypes.number, | ||
alt: PropTypes.string, | ||
}; |