import { h, Component } from 'preact'; import { SingleRepo } from './singleRepo'; export class GithubRepos extends Component { state = { repos: [], erroredOut: false, }; componentDidMount() { this.getGithubRepos(); } getGithubRepos = () => { fetch(`/github_repos`, { headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, credentials: 'same-origin', }) .then((response) => response.json()) .then((json) => { this.setState({ repos: json }); }) .catch(() => { this.setState({ erroredOut: true }); }); }; render() { const { repos, erroredOut } = this.state; const allRepos = repos.map((repo) => ( )); if (erroredOut) { return (
An error occurred. Please check your browser console and email yo@dev.to for more help.
); } if (repos.length > 0) { return
{allRepos}
; } return
; } } GithubRepos.displayName = 'GitHub Repositories Wrapper';