Created
April 1, 2021 18:23
-
-
Save polyglotdev/a878414e189e2a669361194f471e8400 to your computer and use it in GitHub Desktop.
axios call to api
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
import './App.css' | |
import withListLoading from './components/withListLoading' | |
import List from './components/List' | |
import React, { useEffect, useState } from 'react' | |
function App() { | |
const ListLoading = withListLoading(List) | |
const [appState, setAppState] = useState({ | |
loading: false, | |
repos: null | |
}) | |
useEffect(() => { | |
setAppState({ loading: true }) | |
const apiUrl = `https://api.github.com/users/polyglotdev/repos` | |
fetch(apiUrl) | |
.then((response) => response.json()) | |
.then((repos) => { | |
setAppState({ loading: false, repos: repos }) | |
}) | |
}, [setAppState]) | |
return ( | |
<div className="App"> | |
<div className="container"> | |
<h1>My Repositories</h1> | |
</div> | |
<div className="repo-container"> | |
<ListLoading isLoading={appState.loading} repos={appState.repos} /> | |
</div> | |
<footer> | |
<div className="footer"> | |
Built{' '} | |
<span role="img" aria-label="love"> | |
💚 | |
</span>{' '} | |
with by Dom 'Polyglotdev' Hallan | |
</div> | |
</footer> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment