Skip to content

Instantly share code, notes, and snippets.

@ealipio
Created August 15, 2019 06:00
Show Gist options
  • Save ealipio/9778564a626d6d0b4f92c6c544725d04 to your computer and use it in GitHub Desktop.
Save ealipio/9778564a626d6d0b4f92c6c544725d04 to your computer and use it in GitHub Desktop.
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