Skip to content

Instantly share code, notes, and snippets.

@pmqa pmqa/Posts.js
Created Jan 11, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.