Download react-redux-realworld-example-app/src/components/Article/CommentInput.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/Article/CommentInput.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/Article/CommentInput.js
-
curl -L -o CommentInput.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-redux-realworld-example-app/src/components/Article/CommentInput.js
1.52 kB
| import React from 'react'; | |
| import agent from '../../agent'; | |
| import { connect } from 'react-redux'; | |
| import { ADD_COMMENT } from '../../constants/actionTypes'; | |
| const mapDispatchToProps = dispatch => ({ | |
| onSubmit: payload => | |
| dispatch({ type: ADD_COMMENT, payload }) | |
| }); | |
| class CommentInput extends React.Component { | |
| constructor() { | |
| super(); | |
| this.state = { | |
| body: '' | |
| }; | |
| this.setBody = ev => { | |
| this.setState({ body: ev.target.value }); | |
| }; | |
| this.createComment = ev => { | |
| ev.preventDefault(); | |
| const payload = agent.Comments.create(this.props.slug, | |
| { body: this.state.body }); | |
| this.setState({ body: '' }); | |
| this.props.onSubmit(payload); | |
| }; | |
| } | |
| render() { | |
| return ( | |
| <form className="card comment-form" onSubmit={this.createComment}> | |
| <div className="card-block"> | |
| <textarea className="form-control" | |
| placeholder="Write a comment..." | |
| value={this.state.body} | |
| onChange={this.setBody} | |
| rows="3"> | |
| </textarea> | |
| </div> | |
| <div className="card-footer"> | |
| <img | |
| src={this.props.currentUser.image} | |
| className="comment-author-img" | |
| alt={this.props.currentUser.username} /> | |
| <button | |
| className="btn btn-sm btn-primary" | |
| type="submit"> | |
| Post Comment | |
| </button> | |
| </div> | |
| </form> | |
| ); | |
| } | |
| } | |
| export default connect(() => ({}), mapDispatchToProps)(CommentInput); | |