I have a json file where I store paths for my svg icons and other information that I want to display. In a component I map over the data stored in that file. It displays all the data I store there except for the images. When I import the svg directly in the component like this
import img from '../icons/france.svg';
with the same path that is stored in json file and use the variable in the src attribute <img className="lang_icon" src={img}/>)
then the svg is shown. Do you happen to know how to solve this?
Here you have json file structure:
[
{
"id":0,
"language": "English",
"level":5,
"img":"../icons/france.svg"
},
{
"id":1,
"language": "Spanish",
"level":5,
"img": "../icons/france.svg"
},
{
"id":2,
"language": "Italian",
"level":4,
"img":"../icons/france.svg"
},
{
"id":3,
"language": "French",
"level":3,
"img": "../icons/france.svg"
},
{
"id":4,
"language": "Portuguese",
"level":2,
"img": "../icons/france.svg"
}
]
And my component structure:
import React from 'react'
import './Styles.css'
import communicationImg from '../images/communication.svg';
import dataLanguages from '../data/languagesData.json';
import { faStar } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
function Languages()
{
return(
<div id='languages'>
<h2>Languages</h2>
<img className="images" src={communicationImg} alt="communicationImg"/>
<div className="lang_content">
{
dataLanguages.map((element)=>{
return(
<>
<div className="lang_container">
<div className="lang_img">
<img className="lang_icon" src={element.img}/>
</div>
<div className="lang_label">{element.language}</div>
<div className="rating">
{
[...Array(element.level).keys()].map(()=><FontAwesomeIcon icon={faStar}></FontAwesomeIcon>)
}
</div>
</div>
</>
)
})
}
</div>
</div>
)
}
export default Languages
This is what I see:
This is how it should look like: