Created
September 10, 2017 03:37
-
-
Save zzarcon/99a8feb75015c503441f41330c60f4d4 to your computer and use it in GitHub Desktop.
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
class ImgDimensions extends React.Component { | |
state = {width: 0, height: 0, errored: false}; | |
constructor() { | |
this.onLoad = this.onLoad.bind(this); | |
this.onError = this.onError.bind(this); | |
} | |
onLoad({target: {height, width}}) { | |
this.setState({width, height}); | |
} | |
onError() { | |
this.setState({errored: true}); | |
} | |
render() { | |
const {width, height} = this.state; | |
return ( | |
<div> | |
<div>{width}x{height}</div> | |
<img onLoad={this.onLoad} onError={this.onError} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment