Skip to content

Instantly share code, notes, and snippets.

@polyglotdev
Created April 1, 2021 18:23
Show Gist options
  • Save polyglotdev/a878414e189e2a669361194f471e8400 to your computer and use it in GitHub Desktop.
Save polyglotdev/a878414e189e2a669361194f471e8400 to your computer and use it in GitHub Desktop.
axios call to api
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