Skip to content

Instantly share code, notes, and snippets.

@CITGuru
Created August 15, 2019 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CITGuru/e9e76a13bc9a7562dcf7df7c48993393 to your computer and use it in GitHub Desktop.
Save CITGuru/e9e76a13bc9a7562dcf7df7c48993393 to your computer and use it in GitHub Desktop.
List Component
import React, { useState, useEffect } from "react";
import axios from "axios";
const List = () => {
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 mb-2">
{data.map((article, key) => (
<li className="list-group-item" key={key}>
<a href={article.url} target="_blank">
{article.title}
</a>
</li>
))}
</ul>
</>
);
};
export default List;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment