@@ -2,12 +2,13 @@ import React, { useState } from "react";
2
2
import PropTypes from "prop-types" ;
3
3
import "../styles/post.css" ;
4
4
5
- const Post = ( { postData} ) => {
5
+ const Post = ( { postData, handleUpvote } ) => {
6
6
const { title, author, date, isPublished, body, tags} = postData ;
7
7
const [ count , setCount ] = useState ( 0 ) ;
8
8
9
- const handleClick = ( ) => {
9
+ const handleClick = ( event ) => {
10
10
setCount ( prev => prev + 1 )
11
+ handleUpvote ( event . target . value )
11
12
}
12
13
13
14
return (
@@ -18,7 +19,7 @@ const Post = ({postData}) => {
18
19
</ div >
19
20
< div className = "post-counter" >
20
21
< span > Upvotes: { count } </ span >
21
- < button onClick = { handleClick } type = "button" > Upvote this</ button >
22
+ < button onClick = { handleClick } value = { title } type = "button" > Upvote this</ button >
22
23
</ div >
23
24
< div className = "post-author" > Author: { author } </ div >
24
25
< div className = "post-date" > Published: { date } </ div >
@@ -40,7 +41,8 @@ Post.propTypes = {
40
41
isPublished : PropTypes . bool ,
41
42
tags : PropTypes . arrayOf ( PropTypes . string ) ,
42
43
title : PropTypes . string ,
43
- } ) . isRequired
44
+ } ) . isRequired ,
45
+ handleUpvote : PropTypes . func . isRequired
44
46
}
45
47
46
48
export default Post ;
0 commit comments