Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React js image not loading

Here is the directory:

enter image description here

import {useRef} from "react"
import {FaBars, FaTimes} from "react-icons/fa"
import "../css/navbar.css"

export function Navbar() {
    const navRef = useRef()

    const showNavBar = () => {
        navRef.current.classList.toggle("responsive-nav");
    }

    return (
        <navbar>
            <img src="my-app/public/images/logos/word logo trans-preview.png" />
            <nav ref={navRef}>
                <a href="/#">Home</a>
                <a href="/#">Services</a>
                <a href="/#">About</a>
                <a href="/#" className="bottom">Contact</a>
                <button className="nav-btn nav-close-btn" onClick={showNavBar}>
                    <FaTimes/>
                </button>
            </nav>
            <button className="nav-btn" onClick={showNavBar}>
                <FaBars/>
            </button>
        </navbar>
    )
}

the file location is correct and the code should be correct. Why isn’t it loading? everything else is working fine…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried moving it to different folders, I tried getting a new pc, I moved homes… Please i need help 🙁

>Solution :

In React, you can get the image path in public directory directly.
Also, you need to use hyphens or underscores instead of spaces because they may cause problems with loading the image.

For example:

<img src="/images/logos/word-logo-trans-preview.png" />

instead of:

<img src="my-app/public/images/logos/word logo trans-preview.png" />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading