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

151
Visualizações
am trying to display the gifs in ui by clicking on perticular gif, when am fetch the data by map am getting type error

this is how am getting the id of a gif by clicking on them, but am getting this error Uncaught TypeError: Cannot read properties of undefined (reading 'fixed_height'), I want to display fixed_height in UI.

<>
  {Object.keys(gifs).length === 0 ? (
    <div>loading...</div>
  ) : (
    <div className="gif-section">
      {gifs.data.map((items) => {
        return (
          <a href="#" className="image-gifs" key={items.id}>
            <img
              className="live-gifs"
              onClick={() => getGifId(items.id)}
              src={items.images.fixed_height.url}
              alt="..."
            />
          </a>
        );
      })}
    </div>
  )}
</>

here am fetching the gif by id and displaying it.

enter image description here

import axios from "axios";
import { useState } from "react";
import { useEffect } from "react";

const GifInText = ({ gifId }) => {
  const [post, setPost] = useState({});
  console.log("post:", post);

  const fetchData = async () => {
    axios
      .get(`https://api.giphy.com/v1/gifs/${gifId}`, {
        params: {
          api_key: "Xoa3mXrWxKXw6lJscrKUTsbZsXLbGuGY",
          gif_id: gifId
        }
      })
      .catch((error) => {
        console.log("error at fetching gifID2", error);
      })
      .then((response) => {
        setPost(response.data);
      });
  };
  useEffect(() => {
    fetchData();
  }, []);

  return (
    <div>
      {Object.values(post).length &&
        Object.values(post).map((items) => {
          return (
            <>
              <h1>{items.id}</h1>
              <img
                className="live-gifs"
                src={items.images.fixed_height.url}
                alt="..."
              />
            </>
          );
        })}
    </div>
  );
};
export default GifInText;

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As per the image you shared. If post is an object with a single gif data, you can simple use post.data.url instead of items.images.fixed_height.url and looping through Object.values(post).

{post.data.url && (
        <>
          <h1>{post.id}</h1>
          <img
            className="live-gifs"
            src={post.data.url}
            alt="..."
          />
        </>
      )}
about 4 years ago · Juan Pablo Isaza 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