Skip to content

Commit

Permalink
show list of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Apr 13, 2017
1 parent 6e20e17 commit 9844899
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions blog/src/components/posts_index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { fetchPosts } from '../actions';
Expand All @@ -7,13 +8,30 @@ class PostsIndex extends Component {
this.props.fetchPosts();
}

renderPosts() {
return _.map(this.props.posts, post => {
return (
<li className="list-group-item" key={post.id}>
{post.title}
</li>
);
});
}

render() {
return (
<div>
Posts Index
<h3>Posts</h3>
<ul className="list-group">
{this.renderPosts()}
</ul>
</div>
);
}
}

export default connect(null, { fetchPosts })(PostsIndex);
function mapStateToProps(state) {
return { posts: state.posts };
}

export default connect(mapStateToProps, { fetchPosts })(PostsIndex);

0 comments on commit 9844899

Please sign in to comment.