Last active
December 3, 2019 00:55
-
-
Save CITGuru/5650cfb81eea48f6b5fc4e1d9722d7c4 to your computer and use it in GitHub Desktop.
React Component - Article (useInfiniteScroll)
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"; | |
const Article = () => { | |
const url = "https://medrum.herokuapp.com/articles"; | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
axios.get(url).then(res => { | |
setData(res.data); | |
}); | |
}, []); | |
if (!data) { | |
return <div>Loading...</div>; | |
} | |
return ( | |
<> | |
<ul className="list-group-ul"> | |
{data.map((article, key) => ( | |
<li className="list-group-li" key={key}> | |
<a href={article.url} target="_blank"> | |
{article.title} | |
</a> | |
</li> | |
))} | |
</ul> | |
</> | |
); | |
}; | |
export default Article; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment