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;
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Simpler React component design with the Chain of Responsibility pattern
Replies for: Hi guico33, Thanks for taking the time to read the post, and also thanks for the feedback! Considering the above example, what would be the correc...
For further actions, you may consider blocking this person and/or reporting abuse