I'm trying to feed image path through property path
and render it. I have many images and I want to set the image in runtime
so I cannot use pre import
the image prior to rendering. But the image does not show.
Error: cannot find module
(but path is correct)
but when I replace the varible path
to actual path as var imageName = require('./Assets/profpicjpg.jpg').default;
then image shows up, but I wanna use the variable path
to feed the variable path data
Rendering this
import Profpic1 from './Components/Public-page/Profile-card';
function App() {
return (
<div className="App">
<Profpic1
path = './Assets/profpicjpg.jpg'
/>
</div>
)
}
export default App;
Function (this is in a different page)
export default function Profpic1 ({path})
{
var imageName = require(path).default;
return (
<div>
<img src={imageName} />
</div>
)}