I m trying to pass host URL like this http://localhost:1337
from one central file to all the image tags in all components. Currently I am able to render my images like this below.
<img
style={{ height: "212px" }}
src={`http://localhost:1337${props.data.image1.url}`}
alt="new"
/>{" "}
Would love to achieve something like this below -
const API_URL = 'http://localhost:1337' //in one random file like .env in NodeJS at root
and all my Image tags get Images from there
Currently doing this way inside one component and it works.
export default function Home(props) {
const API_URL = 'http://localhost:1337';
return(
<img
style={{ height: "212px" }}
src={`http://localhost:1337${props.data.image1.url}`}
alt="new"
/>{" "})
...rest of the code here
)
}
Currently its throwing error. Something wrong with my Syntax.
Note: My images are in cloud and not in Public Folder which I could reference like process.env.PUBLIC ...
Thanks in advance.