Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda