import { useState, useEffect } from 'react'; import ProjectComponent from '../ProjectComponent'; type PhotoData = { id: number, name: string, imageUrl: string, dateTaken: Date } export default function RecentPhoto() { const [ data, setData ] = useState(null); const [ loading, setLoading ] = useState(true); const [ errorState, setErrorState ] = useState(null); useEffect(() => { fetch("https://api.alexav.gg/v4/social/photos", { method: 'get', headers: { 'content-type': 'application/json' } }) .then(async (res) => { if (res.ok) { console.log("ok!") const json = await res.json() setData(json.data[0]); setLoading(false) } else { console.log("not ok :(") setErrorState("Failed to fetch data!"); setLoading(false); } }) .catch((e) => { setLoading(false); setErrorState(e.message) }) }, []); useEffect(() => { console.log(data) }, [data]) const parseDate = (date: Date) => { const jsDate = new Date(date); return `${jsDate.getFullYear()}/${jsDate.getMonth() + 1}/${jsDate.getDate()}`; } if (data && !loading) { return ( ) } else { return ( <>

No data :(

Check out photos.alexav.gg if this isn't working.

{errorState}

) } }