My code
import React, { Component } from 'react';
import './App.css';
class App extends Component {
state = {
loaded: false,
error: false
}
onImageLoad = () => {
this.setState({
loaded: true
})
}
onImageError = () => {
this.setState({
error: true
});
}
render() {
// let imgSrc = (!error) ? src: fallbackSrc
return (
<div>
<img src= {'https://unsplash.com/photos/wQLAGv4_OYs'} alt={'Wresting Character'} onLoad={() => this.onImageLoad()} onError={require('../src/images/batista.jpg')} />
</div>
)
}
}
export default App;
I want to show the fallback image if the url is broken. Right now the default image shows but if I change the url of it the page throws an error. How do I get to show the dummy image incase if my link is broken.