Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import ImageError from 'app/components/image/ImageError';
  3.  
  4. type Props = {
  5. src: string,
  6. };
  7.  
  8. type State = {
  9. hasError: boolean,
  10. };
  11.  
  12. export default class Image extends Component {
  13. props: Props;
  14.  
  15. state: State = {
  16. hasError: false,
  17. };
  18.  
  19. onErrror = () => this.setState({ hasError: true });
  20.  
  21. render() {
  22. const { src, ...props } = this.props;
  23. const { hasError } = this.state;
  24.  
  25. if (hasError) {
  26. return (<ImageError />);
  27. }
  28.  
  29. return (
  30. <img
  31. {...props}
  32. src={src}
  33. onError={this.onError}
  34. />
  35. )
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement