@@ -2,12 +2,13 @@ import React, { useState } from "react";
22import PropTypes from "prop-types" ;
33import "../styles/post.css" ;
44
5- const Post = ( { postData} ) => {
5+ const Post = ( { postData, handleUpvote } ) => {
66 const { title, author, date, isPublished, body, tags} = postData ;
77 const [ count , setCount ] = useState ( 0 ) ;
88
9- const handleClick = ( ) => {
9+ const handleClick = ( event ) => {
1010 setCount ( prev => prev + 1 )
11+ handleUpvote ( event . target . value )
1112 }
1213
1314 return (
@@ -18,7 +19,7 @@ const Post = ({postData}) => {
1819 </ div >
1920 < div className = "post-counter" >
2021 < span > Upvotes: { count } </ span >
21- < button onClick = { handleClick } type = "button" > Upvote this</ button >
22+ < button onClick = { handleClick } value = { title } type = "button" > Upvote this</ button >
2223 </ div >
2324 < div className = "post-author" > Author: { author } </ div >
2425 < div className = "post-date" > Published: { date } </ div >
@@ -40,7 +41,8 @@ Post.propTypes = {
4041 isPublished : PropTypes . bool ,
4142 tags : PropTypes . arrayOf ( PropTypes . string ) ,
4243 title : PropTypes . string ,
43- } ) . isRequired
44+ } ) . isRequired ,
45+ handleUpvote : PropTypes . func . isRequired
4446}
4547
4648export default Post ;
0 commit comments