How to detect when a image is loaded, that is provided via props, and change state in React?
- 阅读更多 关于 How to detect when a image is loaded, that is provided via props, and change state in React?
问题 I want to load a different image(fake avatar) while the final avatar image is loading. The idea is to detect when the prop image is loaded and change a state. Is it possible? Some ideas? Thank you! class ImageUser extends React.Component { constructor(props) { super(props); this.state = {userImageLoaded: false}; let imageSrc = ""; if (!this.props.userImage) { imageSrc = this.props.noUserImage; } else { imageSrc = this.props.userImage; } this.loadingImage = <img className={styles.imageUser}