Im trying display images im fetching from API
btw url is defined
fetch(url).then((res) => {
res.blob()
.then((img) => {
console.log(img)
const objectURL = URL.createObjectURL(img);
const url = objectURL.replace(/[blob:]{5}/gi,'')
ReactDOM.render(<Gallery photos={url} />, document.getElementById('root'));
});
})
Gallery.js
import React, { Component } from 'react';
class Gallery extends Component {
constructor (props) {
super(props);
this.state = {
Images: []
}
}
componentDidMount () {
this.setState({images: this.props.photos});
}
render() {
const {image} = this.props.photos;
return (
<div >
<img
className="App"
width="300"
height="300"
src={image}
alt="dogs"/>
</div>
);
}
}
export default Gallery;
with or without the regex /[blob:]{5}/gi it is only displaying the alt prop and not the image. The image is received and the get call is successful but the objectURL url is not working. Any help?