Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Unable to get images from the images folder using img tag

I am trying to display images for each object inside categoryDictonary and later display it using the html tag <img src=items.image />. However I am unable to get the desired image.
What am I doing wrong?

I would've just used links to images but the links are very very lengthy and they make the code look/feel clumsy as well.
I think its good practice to have a seperate folder for images but I'm unable to implement the same.

import { useState } from "react";
import "./styles.css";

export default function App() {
  var categoryDictonary = {
    Marvel: [
      {
        name: "WandaVision",
        image: "Images/Wanda.jfif",
        rating: 10
      },
      { name: "Loki", image: "Loki.jfif", rating: 9.5 },
      { name: "Moon Knight", image: "Images/MoonKnight.jfif", rating: 8 }
    ],
    SitComs: [
      {
        name: "Brooklyn 99",
        image: "Images/Wanda",
        rating: 10
      },
      {
        name: "Bing Bang Theory",
        image: "Images/Loki",
        rating: 7
      },
      {
        name: "Friends",
        image: "Image/Wanda",
        rating: 7
      }
    ]
  };

  var categories = Object.keys(categoryDictonary);
  var [category, setCategory] = useState("Marvel");
  function ClickHandler({ item }) {
    console.log(item);
    setCategory(item);
    console.log("Categoty is" + category);
  }

  return (
    <div className="App">
      <h2>TV Show Ratings</h2>
      <h3>Check out my ratings on some of the most popular TV Shows</h3>
      <ul>
        {categories.map((item) => {
          return (
            <li
              id="Categories"
              key={item}
              onClick={() => ClickHandler({ item })}
            >
              {item}
            </li>
          );
        })}
      </ul>
//List to display all shows of a given category
      <ul id="ShowList">
        {categoryDictonary[category].map((items) => {
          return (
            <li id="Shows" key={items.name}>
//Gives the name of the show
              <div>{items.name}</div>
//Gives the image of the show
              <div>
                <img src={items.image} />
              </div>
//Gives the rating of the show
              <div>Rating:{items.rating}</div>
            </li>
          );
        })}
      </ul>
    </div>
  );
}

Here is the corresponding output to my code:

Current output of my code

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda