Originally had issues with an image loop (it was killing our api calls) and realized we needed to remove componentDidUpdate. Now when inspecting the page with React Dev Tools I can see everything except for the img src updates including the alt tag. If nothing has been rendered to the page then it will render the information correctly but once something is there it changes everything except for the image its self.
class Img extends Component {
constructor(props) {
super(props)
this.state = {
src: ""
}
}
// componentDidUpdate() {
// this.getImageId();
// }
componentDidMount() {
this.getImageId();
}
getImageId() {
axios.get(`http://localhost:4000/api/images/${this.props.src}`)
.then(response => {
console.log(response.data) //this shows only on first request
this.setState({
src: response.data
})
})
.catch(err => console.log(err))
}
render() {
return ( <img src = {
this.state.src
}
alt = {
this.props.alt
}
style = {
{
height: "150px",
width: "200px",
borderRadius: "10px"
}
}
/>
)
}
}