I am working on a React project where I need to use a JSON file to retrieve data.
Everything is going smoothly except for the fact that I cannot display any logo from my JSON object.
This is the part of my Component where I try to display the logo:
Well, to break it down for clarification: ./images/photosnap.svg' suggests there is another folder named images in the same location as this component calling it, which contains a file named photosnap.svg.
Have a look in your console to see if there are any permission related errors to do with the location/images.
Yes, I just pushed the most recent version.
You can find it : here
Also, you’ll need to run npm install react-bootstrap bootstrap because I’m using a lost of react-boostrap Components.
In the Browser console you’ll see an Error displayed as Warning for some reasons saying " Each child in a list should have a unique “key” prop. "
But if you look up the React Developer tool, you’ll see that all my key are unique.
Thank you, for linking that. However, I cannot see any components in your repo?
Nevermind. I found it in the other branch.
I cannot see any issue that would prevent the logo from being shown. Back to your warning message:
You have not assigned the parent element the key. You need to do this.
svg cannot be rendered as a source in an img element in react like this. You are going to have to have a separate loop, going through each logo, importing each image directly. The same way you import a component.
Oh God… I thought about this earlier… But I was looking in the wrong place.
I asked myself “could the src prop of : <img src="" /> actually display .svg?”
Instead I should’ve searched from the React side of things…
I found another way of displaying images/logos from JSON/JS Objects.
I’m just going to post my solution here since it took some time for me to find this fix, hopefully the next ones with the same issue are going to be able to solve it faster
Hello lainth and hello everyone, since I know for sure how crazy this type of problem can I wanted to submit this solution to all of you, do not modify the .json file, and insert this function in the map function and return the require of your image like this :