import { useState, useEffect } from 'react'; import ProjectComponent from '../ProjectComponent'; type SteamAPIResponse = { data: GameItem[] } type GameItem = { appid: number, name: string, playtime_forever: number, img_icon_url: string, } export default function RecentGame() { const [ data, setData ] = useState(); const [ errorState, setErrorState ] = useState(""); const [ loading, setLoading ] = useState(true); const translateToAppStorePage = (appId: number) => { return "https://store.steampowered.com/app/" + appId } const buildMediaUrl = (appId: number, hash: string) => { return "https://media.steampowered.com/steamcommunity/public/images/apps/" + appId + "/" + hash + ".jpg" } useEffect(() => { fetch("https://api.alexav.gg/v4/social/steam", { method: "get" }) .then(async (res) => { if (res.ok) { const data = await res.json() as SteamAPIResponse setData(data.data); } else { setErrorState("Failed to load! :(") } }) .catch((e: Error) => { setErrorState(e.message) }) setLoading(false); }, []); if (!loading && data) { return ( ) } else { <>

No data :(

Check out steamcommunity.com/id/luvxavierr if this isn't working.

{errorState}

} }