Created
August 15, 2019 06:00
-
-
Save ealipio/9778564a626d6d0b4f92c6c544725d04 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 React, { useState, useEffect } from 'react'; | |
import axios from 'axios'; | |
function App() { | |
const [data, setData] = useState({ hits: [] }); | |
useEffect(() => { | |
const fetchData = async () => { | |
const result = await axios( | |
'https://hn.algolia.com/api/v1/search?query=redux' | |
); | |
setData(result.data); | |
}; | |
fetchData(); | |
}, []); | |
return ( | |
<React.Fragment> | |
<h3>Fetching from Hooks</h3> | |
<ul> | |
{data.hits.map(item => ( | |
<li key={item.objectID}> | |
<a href={item.url}>{item.title}</a> | |
</li> | |
))} | |
</ul> | |
</React.Fragment> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment