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

Image not getting displayed in react project

This is my App.js. Here, I call the "Profile" Component.

import './App.css';
import Profile from "./Profile"

function App() {
  return (
    <div className="App">
      <Profile />
    </div>
  );
}

export default App;

Then, inside Profile.js, I call Card component and inside the Card component, I’ve enclosed an image.

import React from 'react'
import Card from './Card'
import styles from "./Profile.module.css"
import image1 from "./assets/profile1.png"
const Profile = () => {
  return (
    <Card>
      <div>
        <img src={image1} alt="" />
      </div>

    </Card>
  )
}

export default Profile

Inside of Card component, I’ve just applied some CSS to make it look like a Card.

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

import React from 'react'
import styles from "./Card.module.css"

const Card = () => {
  return (
    <div className={styles.card}>

    </div>
  )
}export default Card

This is my folder structure.

enter image description here

I’m really confused why the image isn’t getting showed up. Currently this is the output I’m getting.

enter image description here

I’ve restarted the server as well. But it’s not getting fixed.

>Solution :

your card doesn’t have a child component return maybe that could be the problem

    import React from 'react'
    import styles from "./Card.module.css"
    
    const Card = ({children}) => {
      return (
        <div className={styles.card}>
    {children}
        </div>
      )
    }
export default Card

try this

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