Created
August 29, 2018 08:53
-
-
Save gladchinda/1292ba705454128825f33c309bb75685 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 from 'react'; | |
import { connect } from 'react-redux'; | |
import { updateComment, deleteComment } from './actions'; | |
function Comment(props) { | |
const { id, content } = props.comment; | |
// Invoking the actions directly as component props | |
const editComment = () => props.updatePostComment(id, content); | |
const removeComment = () => props.deletePostComment(id); | |
return ( | |
<div> | |
<p>{ content }</p> | |
<button type="button" onClick={editComment}>Edit Comment</button> | |
<button type="button" onClick={removeComment}>Remove Comment</button> | |
</div> | |
) | |
} | |
// Object of action creators | |
const mapDispatchToProps = { | |
updatePostComment: updateComment, | |
deletePostComment: deleteComment | |
} | |
export default connect(null, mapDispatchToProps)(Comment); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment