Skip to content

Instantly share code, notes, and snippets.

@SafaElmali
Last active April 18, 2025 16:17
Show Gist options
  • Save SafaElmali/99c646418ce6cc2493a3f4ebe4c46510 to your computer and use it in GitHub Desktop.
Save SafaElmali/99c646418ce6cc2493a3f4ebe4c46510 to your computer and use it in GitHub Desktop.
useEffect(() => {
const fetchTrendingGifs = async () => {
try {
const response = await fetch(
`https://api.giphy.com/v1/gifs/trending?api_key=${import.meta.env.VITE_GIPHY_API_KEY}&limit=25`
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
setGifs(data.data);
setLoading(false);
} catch (error) {
handleError(error as Error);
}
};
fetchTrendingGifs();
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment