AllenYuan

http - articlepreview - integration

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