Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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