Answers for "check if image is still loading reactjs"

1

check if image is still loading reactjs

class App extends React.Component {
  constructor(){
    super();
    this.state = {loaded: false};
  }

  render(){
    return (
      <div>
        {this.state.loaded ? null :
          <div
            style={{
              background: 'red',
              height: '400px',
              width: '400px',
            }}
          />
        }
        <img
          style={this.state.loaded ? {} : {display: 'none'}}
          src={this.props.src}
          onLoad={() => this.setState({loaded: true})}
        />
      </div>
    );
  }
}

ReactDOM.render(<App src={`http://placehold.it/400x400`} />, document.getElementById('root'));
Posted by: Guest on March-22-2021

Code answers related to "check if image is still loading reactjs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language