Created
February 21, 2019 13:35
-
-
Save fernandoperigolo/9bfd6d6b581ffd4e9e854da92607bd8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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