/**
 * @author lvzhiyi
 *
 * @description img加载组件
 */
import React, { Component } from 'react';
import './style.styl';
interface Props {
    src: string;
    place?: string;
}

interface State {
    error: boolean;
}

class Img extends Component<Props, State> {
    constructor(props: Props) {
        super(props);
        this.state = {
            error: false
        };
    }
    render() {
        const { src, place } = this.props;
        return this.state.error && !place ? (
            <div className="instead-img" />
        ) : (
            <img
                className="img-load"
                src={src && !this.state.error ? src : place}
                onError={() => {
                    this.setState({ error: true });
                }}
                alt=""
            />
        );
    }
}

export default Img;
