Skip to content

Instantly share code, notes, and snippets.

@chaseholdren
Created August 4, 2019 13:15
Show Gist options
  • Select an option

  • Save chaseholdren/36628236b1dd86b2f1d92e49284aefb2 to your computer and use it in GitHub Desktop.

Select an option

Save chaseholdren/36628236b1dd86b2f1d92e49284aefb2 to your computer and use it in GitHub Desktop.
import React from "react";
class ArticleList extends React.Component {
constructor(props) {
super(props);
this.state = { articles: [] };
}
async componentDidMount() {
const result = await fetch("http://sample.com/");
const articles = await result.json();
this.setState({ articles: articles });
}
renderArticle = article => {
if (!article.visible) return <React.Fragment />;
if (article.loading) return <div className="article skeleton" />;
return <div className="article">{article.title}</div>;
};
render() {
return this.state.articles.map(renderArticle);
}
}
export default ArticleList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment