Skip to content
Advertisement

Displaying images from fetch API call Node/React

Im trying display images im fetching from API btw url is defined

JavaScript

Gallery.js

JavaScript

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?

Advertisement

Answer

const {image} = this.props.photos; is equivalent to

JavaScript

It means, “assign the property image of this.props.photos to the variable image.

However, this.props.photos is a string. Strings don’t have a image property. You simply want

JavaScript

You are not doing anything with this.state.Images, so you can remove the constructor and componentDidMount.


/[blob:]{5}/gi doesn’t do what you want it to do. It means “match all sequences of 5 characters that consist of b, l, o or :

I.e. the character sequence bb:ol would match.

If you wanted to remove the sequence blob: at the beginning of the string, then you should be using /^blob:/i instead.

However, you shouldn’t remove blob: from the URL.


Complete and simplified example

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement