skip to Main Content

this is the code

import React from "react";
import ReactDOM from "react-dom/client";

const Header = () => {
  return (
    <div className="header">
      <div className="logo-container">
        <img className="logo" src="/assets/logo.jpg" />
      </div>
      <div className="nav-items">
        <ul>
          <li>Home</li>
          <li>About us</li>
          <li>Contact us</li>
          <li>Cart</li>
        </ul>
      </div>
    </div>
  );
};

const AppLayout = () => {
  return (
    <div className="App">
      <Header />
    </div>
  );
};

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<AppLayout />);

It is what i am getting

please help me as i am new to react.

i am expecting an image to be displayed on the server

2

Answers


  1. Try to add an alt tag to your code above, if it still doesn’t work
    Try this:

    import React from "react";
    import ReactDOM from "react-dom/client";
    
    const Header = () => {
      return (
        <div className="header">
          <div className="logo-container">
            <img className="logo" src={process.env.PUBLIC_URL + "/assets/logo.jpg"} alt="Logo" />
          </div>
          <div className="nav-items">
            <ul>
              <li>Home</li>
              <li>About us</li>
              <li>Contact us</li>
              <li>Cart</li>
            </ul>
          </div>
        </div>
      );
    };
    
    const AppLayout = () => {
      return (
        <div className="App">
          <Header />
        </div>
      );
    };
    
    const root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(<AppLayout />);
    
    Login or Signup to reply.
  2. import logo on the top separately and give to src of img tag:

    import React from "react";
    import ReactDOM from "react-dom/client";
    //exact logo path down below//
    import logo from "../assets/myLogo.png";
    
    const Header = () => {
      return (
        <div className="header">
          <div className="logo-container">
            <img className="logo" src={logo} />
          </div>
          <div className="nav-items">
            <ul>
              <li>Home</li>
              <li>About us</li>
              <li>Contact us</li>
              <li>Cart</li>
            </ul>
          </div>
        </div>
      );
    };
    
    const AppLayout = () => {
      return (
        <div className="App">
          <Header />
        </div>
      );
    };
    
    const root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(<AppLayout />);
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search