Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question