'Am building the facebook post in react. and am almost done, but am getting trouble to figure how to close the selected gif in text area
I want to close the gif that is displayed in the text area by clicking on the close button, if I do that am not able to get the gif data again. so I want to select the gif every time I close the gif without refreshing.
import axios from "axios";
import { useState } from "react";
import { useEffect } from "react";
import "./componentsStyles/GifInText.css"
const GifInText = ({gifId}) => {
const [post, setPost] = useState({});
const [closeGif, setCloseGif] = useState(false)
const fetchData = async () =>{
await 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 className='gif-section'>
{post.data && (
<>
<div className='image-gifs'>
<i className="fas fa-times" onClick={()=>setCloseGif(!post)}></i>
<img className="live-gifs" src={post.data.images.fixed_height.url} alt="..."/>
</div>
</>
)}
</div>
)
}
export default GifInText;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
