1
Fork 0
mirror of https://github.com/Steffo99/steffoweb.git synced 2024-11-21 23:54:30 +00:00
steffoweb/components/MoreProjects.jsx

41 lines
1.1 KiB
JavaScript

import * as React from "react"
import {Anchor} from "@steffo/bluelib-react"
import Style from "./MoreProjects.module.css"
export function MoreProjects({user, minus}) {
const [data, setData] = React.useState(null)
const [error, setError] = React.useState(null)
const fetchData = React.useCallback(
() => {
fetch(`https://api.github.com/users/${user}`)
.then(r => r.json())
.then(d => setData(d))
.catch(e => setError(e))
},
[user, setData, setError]
)
React.useEffect(
() => {
fetchData()
},
[fetchData]
)
const contents = React.useMemo(
() => {
if(data === null) return "Loading..."
else if(error !== null) return "Error: {error}"
return `...and ${data["public_repos"] - minus} more!`
},
[data, error, minus]
)
return (
<div className={Style.More}>
<Anchor href={"https://github.com/Steffo99?tab=repositories"}>{contents}</Anchor>
</div>
)
}