AllenYuan

homepage - home - articlelist

Apr 22nd, 2020
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2.  
  3. const ArticleList = (props) => {
  4.   // no articles => render loading text
  5.   if (!props.articles) {
  6.     return <div className="article-preview">Loading...</div>;
  7.   }
  8.  
  9.   // no articles => render no articles text
  10.   if (props.articles.length === 0) {
  11.     return <div className="article-preview">No articles are here...yet.</div>;
  12.   }
  13.  
  14.   // have articles => map them to article preview components
  15.   return (
  16.     <div>
  17.       {props.articles.map((article) => {
  18.         return <h2>{article.title}</h2>;
  19.       })}
  20.     </div>
  21.   );
  22. };
  23.  
  24. export default ArticleList;
Advertisement
Add Comment
Please, Sign In to add comment