0

I am rendering HTML using JSX and creating a header which has logo to the left side...but it is coming out to be in the way that is shown in my uploaded photo. I have also uploaded the corresponding code of the component This is the code

this is the website error occuring

Please advice me what to do

I tried to check the network tab in my chrome developer tools...the message showing is 200 OK(I guess which is correct when the image is loaded) and still it is not appearing.

1
  • 4
    It's better to provide the code in the question itself instead of link to image of the code and the website image can be directly added to the question as well.
    – Ahmar
    Commented Jul 21, 2023 at 19:56

1 Answer 1

0
Update:

According to this answer you need to import the image.

import React from 'react';
import img from './istockphoto-1239476413-1024x1024.jpg'

const Title = () => (
  <img 
    className="Logo"
    src={img} 
    alt="logo"
  />
 )

export function App(props) {
  return (
    <div className='App'>
     <div className='header'>
      <Title />
      <div className="nav-items">
        <ul>
          <li>Home</li>
          <li>About</li>
          <li>Contact</li>
          <li>Cart</li>
        </ul>
      </div>
    </div>
    </div>
  );
}

Here's a link to the react playground.

7
  • 1
    Adding return wont make a difference because these are arrow functions and we can run them without the return statements in JSX. Commented Jul 22, 2023 at 6:54
  • No, return is only implied if the statement is without a block. In case of a statement in block (meaning a statement within '{}' braces) an explicit return is required. You can read more about it here. And the solution works on the playground as well.
    – Ahmar
    Commented Jul 22, 2023 at 9:56
  • Yeah, actually my bad I just realized I misinterpreted part of the question. It might be an issue with your image src. You could try "src/img.jpg"?
    – Ahmar
    Commented Jul 22, 2023 at 10:03
  • my image is in the same folder as that of the code file.....and i had tried it even when my image was in some other folder....the problem is still the same!! Commented Jul 22, 2023 at 13:27
  • btw the alt attributes value is getting shown and a sample image is also shown in place of the required image1 Commented Jul 22, 2023 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.