I cant import a photo in my react app, the error says 'Error: Cannot find module './../assets/planet-mercury.svg''
Im using a json file to get the path of the img
My app think that my path looks like this './../assets/planet-mercury.svg', but when I try to log it I see this path './assets/planet-mercury.svg' (which is the path in my json file). Which means my complete path should be something like this '../../assets/planet-mercury.svg'
Code:
const [currentPlanet,setCurrentPlanet]=useState(data[0])
const {name} = useParams();
useEffect(() => {
const planet = data.find((item)=>item.name===name)
setCurrentPlanet(planet);
}, [name])
const photo = require('../.'+currentPlanet.images.planet).default
return (
<section id={planetStyle.planet}>
<div className="container">
<div>
<img alt={currentPlanet.name} src={photo} />
</div>
</div>
</section>
)