Created
January 11, 2018 19:36
-
-
Save pmqa/58f787f277d92d4b7f15a3429f629c86 to your computer and use it in GitHub Desktop.
Posts Component
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 from 'react'; | |
import { connect } from 'react-redux'; | |
import { | |
UPDATE_POST_TITLE | |
} from './../constants/actionTypes'; | |
const mapDispatchToProps = dispatch => ({ | |
updatePostTitle: (payload) => | |
dispatch({ type: UPDATE_POST_TITLE, payload }) | |
}); | |
class Posts extends React.Component { | |
render() { | |
const Posts = this.props.posts.map((post) => { | |
return ( | |
<div className="post"> | |
<h3>{post.title}</h3> | |
<h4>id: {post.id}</h4> | |
<button onClick={() => this.props.updatePostTitle(post)}>Click to update title</button> | |
</div> | |
) | |
}); | |
return ( | |
<div className="posts"> | |
<h1>Posts</h1> | |
{Posts} | |
</div> | |
) | |
} | |
} | |
export default connect(null, mapDispatchToProps)(Posts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment