How can I put image in React

I want to upload image from files in my React application (I use create-react-app).It didn’t show up and the error message appeared.

The error message is

./src/components/pages/TimeTable.js Module not found: Can’t resolve ‘../dance.png’ in ‘/Users/jolly/Desktop/Dance_School_Website-master/src/components/pages’

My files:

--public 
  --images
    --dance.png


import TimeTablePic from "../dance.png";

function TimeTable() {
    return (
        <>
            <img className="TimeTablePic" src={TimeTablePic} alt="TimeTable" />    
            <Footer2 />   
        </> 
    );
}

export default TimeTable;

Answer

simply use

<img className="TimeTablePic" src="images/dance.png" alt="TimeTable" />

Leave a Reply

Your email address will not be published. Required fields are marked *