Skip to content

Instantly share code, notes, and snippets.

@pmqa
Created January 11, 2018 19:36
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 pmqa/58f787f277d92d4b7f15a3429f629c86 to your computer and use it in GitHub Desktop.
Save pmqa/58f787f277d92d4b7f15a3429f629c86 to your computer and use it in GitHub Desktop.
Posts Component
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