Skip to content

Instantly share code, notes, and snippets.

@allpwrfulroot
Created December 11, 2019 19:23
Show Gist options
  • Save allpwrfulroot/07541bd7e97d5651d87986303be7bca9 to your computer and use it in GitHub Desktop.
Save allpwrfulroot/07541bd7e97d5651d87986303be7bca9 to your computer and use it in GitHub Desktop.
Projects index page listing all project .mdx info
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