Skip to content

Instantly share code, notes, and snippets.

@fernandoperigolo
Created February 21, 2019 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandoperigolo/9bfd6d6b581ffd4e9e854da92607bd8b to your computer and use it in GitHub Desktop.
Save fernandoperigolo/9bfd6d6b581ffd4e9e854da92607bd8b to your computer and use it in GitHub Desktop.
import React, { Component, Fragment } from 'react'
import { connect } from 'react-redux'
import { handleGetAllPosts } from '../actions/posts'
class PostList extends Component {
componentDidMount () {
this.props.getAllPosts()
}
render() {
const { posts } = this.props
return (
<Fragment>
{Object.keys(posts).map(postId =>
<p key={postId}>{posts[postId].title}</p>
)}
</Fragment>
)
}
}
const mapDispatchToProps = {
getAllPosts: handleGetAllPosts,
}
function mapStateToProps ({ posts }) {
return {
posts,
}
}
export default connect(mapStateToProps, mapDispatchToProps)(PostList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment