CommentInput.js 608 B

123456789101112131415161718
  1. import { useState } from "react"
  2. import { connect } from "react-redux"
  3. import { actionAddComment } from "../actions"
  4. const CommentInput = ({onPost}) => {
  5. const [comment,setComment] = useState('')
  6. return (
  7. <>
  8. <input type="text" value={comment} onChange={e => setComment(e.target.value)} placeholder="Ваш коментарий" />
  9. <button onClick={()=> comment.length>0 && onPost(comment)}>Добавить коментарий</button>
  10. </>
  11. )
  12. }
  13. const CCommentInput = connect(null,{onPost: actionAddComment})(CommentInput)
  14. export default CCommentInput