Last active
June 22, 2021 15:44
-
-
Save emmaodia/d01dc3a3c8f1fba7452e36cbd21faede to your computer and use it in GitHub Desktop.
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 { useState, useEffect } from "react"; | |
import axios from "axios"; | |
function App() { | |
const [items, setItems] = useState([]); | |
useEffect(() => { | |
getData() | |
}, []) | |
const getData = async () => { | |
//Using fetch | |
const response = await fetch("https://api.covalenthq.com/v1/chains/status/?key=your-api-key") | |
const data = await response.json() | |
setItems(data.data.items) | |
//using axios | |
/** | |
try { | |
const response = await axios.get('https://api.covalenthq.com/v1/chains/status/?key=your-key'); | |
console.log(response.data.data); | |
setItems(response.data.data.items) | |
} catch (err) { | |
// Handle Error Here | |
console.error(err); | |
} | |
**/ | |
} | |
return ( | |
<div className="App"> | |
{console.log(items)} | |
Welcome | |
<ul> | |
{items.map(item => ( | |
<li key={item.chain_id}> | |
{item.name} | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment