Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Created July 31, 2016 14:38
Show Gist options
  • Save nishinoshake/ebf2d32439bbc8013a8058ef36251ee3 to your computer and use it in GitHub Desktop.
Save nishinoshake/ebf2d32439bbc8013a8058ef36251ee3 to your computer and use it in GitHub Desktop.
シンプルなReactコンポーネントのループ
const LatestPostsComponent = props => {
const postPreviews = renderPostPreviews(props.posts);
return (
<section>
<div><h1>Latest posts</h1></div>
<div>
{ postPreviews }
</div>
</section>
);
};
const renderPostPreviews = posts => (
posts.map(post => this.renderPostPreview(post))
);
const renderPostPreview = post => (
<article>
<h3><a href={`/post/${post.slug}`}>{post.title}</a></h3>
<time pubdate><em>{post.posted}</em></time>
<div>
<span>{post.blurb}</span>
<a href={`/post/${post.slug}`}>Read more...</a>
</div>
</article>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment