Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created August 29, 2018 08:57
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 gladchinda/96046bfde7e03d9c840ba4ff48b077a6 to your computer and use it in GitHub Desktop.
Save gladchinda/96046bfde7e03d9c840ba4ff48b077a6 to your computer and use it in GitHub Desktop.
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as commentActions from './actions';
function Comment(props) {
const { id, content } = props.comment;
const { updateComment, deleteComment } = props.actions;
// Invoking the actions from props.actions
const editComment = () => updateComment(id, content);
const removeComment = () => deleteComment(id);
return (
<div>
<p>{ content }</p>
<button type="button" onClick={editComment}>Edit Comment</button>
<button type="button" onClick={removeComment}>Remove Comment</button>
</div>
)
}
const mapDispatchToProps = (dispatch) => {
return {
actions: bindActionCreators(commentActions, dispatch)
}
}
export default connect(null, mapDispatchToProps)(Comment);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment