T
T
testtostertest1112018-12-27 18:58:29
React
testtostertest111, 2018-12-27 18:58:29

How to remove a class from a div when loading an image in react?

There are many divs and img in each of them, when loading an image, you need to remove all classes from the div (in which the image) is, how to do this? I think you need to use onLoad on the picture, but how then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-12-27
@testtostertest111

class ExampleComponent extends React.Component {
  state = {
    isReady: false,
  };
  
  hanldeOnLoad = () => {
    this.setState({ isReady: true });
  };
  
  render() {
    const { src } = this.props;
    const { isReady } = this.state;
 
    const className = isReady ? '' : 'some-class';
 
    return (
      <div className={className}>
        <img onLoad={this.hanldeOnLoad} src={src} />
      </div>
    );
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question