I want to render the star1.png located in src/images/ directory without using import at the top and without using the public directory.
My code:
import React from "react"
import ReactDOM from "react-dom"
class App extends React.Component
{
render(){
let starIcon = "./images/star1.png"
return(
<>
<h1>Hello</h1>
<img src={starIcon} />
</>
)
}
}
ReactDOM.render(<App />, document.getElementById("root"))
Advertisement
Answer
I found the answer to my question which is using require:
let starIcon = require("./images/star1.png")