Moved images folder to public directory to load in React app

📸 A quick React lesson I learned while working on a project! I was building a small React app and added an “images” folder inside the src directory to store some pictures. Everything looked fine — until I tried to display them in my components. No matter what path I used, the images just wouldn’t load! 😅 After some digging, I realized that React doesn’t serve static assets directly from the src folder — it only compiles JavaScript code from there. The correct approach was to move my images folder to the public directory. ✅ Here’s what worked: <img src="/images/profile.png" alt="Profile" /> 💡 Lesson learned: Always keep your static files (like images, icons, or PDFs) in the public folder if you want to access them directly using a path. React’s build process doesn’t include files from src unless they’re imported in JS. It was a small issue, but it helped me understand how React’s build structure actually works. Every bug teaches something new — this one taught me about static asset handling! 🚀 #ReactJS #WebDevelopment #FrontendDeveloper #MERNStack #LearningByDoing #CodingJourney #JavaScript

To view or add a comment, sign in

Explore content categories