Skip to content

Instantly share code, notes, and snippets.

@emmaodia
Last active June 22, 2021 15:44
Show Gist options
  • Save emmaodia/d01dc3a3c8f1fba7452e36cbd21faede to your computer and use it in GitHub Desktop.
Save emmaodia/d01dc3a3c8f1fba7452e36cbd21faede to your computer and use it in GitHub Desktop.
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