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

255
Visualizações
How to display Pokemon image in react js?

I am new in react JS technology , and I got a assignment from my job to display Pokemon name and image , I displayed name but I am Failed with displaying image of Pokemon, Can anyone help me to display image of pokemon. I f you have any query regarding my question please free feel to ask me.

enter image description here

Error get when i add image

import React, { useEffect, useState } from "react";
import Axios from "axios";

const Pokemonapi = () => {
  const [text, setText] = useState("");
  const [data, setData] = useState([]);

  const Search = () => {
    if (text == "") {
      alert("Please Enter a name to be search");
    } else {
      searchPokemon();
      setText("");
    }
  };

  const searchPokemon = async () => {
    const response = await Axios.get(
      `https://pokeapi.co/api/v2/pokemon/${text}`
    );
    //   const getdata = await response.json();
    setData(response.data.results);
    console.log(response);
  };

  useEffect(() => {
    searchPokemon();
  }, []);

  return (
    <div>
      <div className="container-fluid jumbotron">
        <div className="input-group mb-3">
          <input
            type="text"
            className="form-control shadow-none"
            placeholder="Search Pokemon"
            value={text}
            onChange={(e) => setText(e.target.value)}
          />
          <div className="input-group-append">
            <span
              className="input-group-text"
              id="basic-addon2"
              onClick={Search}
            >
              Search
            </span>
          </div>
        </div>
      </div>

      {data.map((dat, index) => {
        return (
          <div key={index}>
            <h2>{dat.name}</h2>
        <img src={dat.sprites.other.dream_world.front_default} />
          </div>
        );
      })}

    </div>
  );
};

export default Pokemonapi;
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It depends on what that api is returning , if it returns the url of the image , you can use
<img src={dat.sprites.other.dream_world.front_default} />, assuming that front_default=url but if it returns a base64 encode of the image , then you need to use

<img src=`data:image/png;base64,${dat.sprites.other.dream_world.front_default}` />
about 4 years ago · Santiago Trujillo Relatório
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