Created
December 11, 2019 19:23
-
-
Save allpwrfulroot/07541bd7e97d5651d87986303be7bca9 to your computer and use it in GitHub Desktop.
Projects index page listing all project .mdx info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Projects() { | |
const [projects, setProjects] = useState([]) | |
const [error, setError] = useState() | |
useEffect(() => { | |
async function fetchProjects() { | |
try { | |
const result = await fetch(`/api/get-projects`) | |
const json = await result.json() | |
setProjects(json.projects) | |
} catch (err) { | |
setError('Error! Please refresh the page?') | |
} | |
} | |
fetchProjects() | |
}, []) | |
if (error) return <p>{error}</p> | |
return ( | |
<> | |
{projects.length > 0 ? ( | |
projects.map(p => <ProjectCard key={p.name} {...p} />) | |
) : ( | |
<p>Loading...</p> | |
)} | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment