MCPcopy
hub / github.com/adrianhajdin/project_web3.0 / useFetch

Function useFetch

client/src/hooks/useFetch.jsx:5–24  ·  view source on GitHub ↗
({ keyword })

Source from the content-addressed store, hash-verified

3const APIKEY = import.meta.env.VITE_GIPHY_API;
4
5const useFetch = ({ keyword }) => {
6 const [gifUrl, setGifUrl] = useState("");
7
8 const fetchGifs = async () => {
9 try {
10 const response = await fetch(`https://api.giphy.com/v1/gifs/search?api_key=${APIKEY}&q=${keyword.split(" ").join("")}&limit=1`);
11 const { data } = await response.json();
12
13 setGifUrl(data[0]?.images?.downsized_medium.url);
14 } catch (error) {
15 setGifUrl("https://metro.co.uk/wp-content/uploads/2015/05/pokemon_crying.gif?quality=90&strip=all&zoom=1&resize=500%2C284");
16 }
17 };
18
19 useEffect(() => {
20 if (keyword) fetchGifs();
21 }, [keyword]);
22
23 return gifUrl;
24};
25
26export default useFetch;

Callers 1

TransactionsCardFunction · 0.85

Calls 1

fetchGifsFunction · 0.85

Tested by

no test coverage detected