I'm creating a website and i want to pass an image url to a component. How do i do it?
I tried:
App.js :
import React from 'react';
import './App.css';
import Elem from './Elem.js';
const App = () => {
return (
<Prod imgUrl="../../url/to/img.png"/>
</div>
);
}
export default App;
Elem.js :
import React from 'react';
import './Elem.css';
const Prod = ({imgUrl}) => {
return (
<div className="elem">
<div className="elemImg">
<img src={require(`${imgUrl}`)} alt="" />
</div>
</div>
);
}
export default Elem;
But it give me error:
Error: Cannot find module '../../url/to/img.png'