Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!