You are viewing a single comment's thread. Return to all comments →
This is my code but test cases failed!
import React, { useState } from "react";
const intialFeedback = [{ name: "Readability", upvote: 0, downvote: 0 }, { name: "Performance", upvote: 0, downvote: 0 }, { name: "Security", upvote: 0, downvote: 0 }, { name: "Documentation", upvote: 0, downvote: 0 }, { name: "Testing", upvote: 0, downvote: 0 }];
const FeedbackSystem = () => { const [feedback, setFeedback] = useState(intialFeedback)
const handleUpVote = (name) => { setFeedback(pre => { return pre.map(item => { if(item.name === name){ item.upvote+=1; }
return item; }); })
}
const handleDownVote = (name) => { setFeedback(pre => { return pre.map(item => { if(item.name === name){ item.downvote+=1; }
return ( {feedback.map((item, index) => {handleDownVote(item.name)}} handleUpVote={()=>{handleUpVote(item.name)}} index={index} {...item} /> )} ); };
export default FeedbackSystem;
function FeedbackCard({ name,upvote, downvote, handleDownVote, handleUpVote, index }) { return (
Seems like cookies are disabled on this browser, please enable them to open this website
Code Review Feedback
You are viewing a single comment's thread. Return to all comments →
This is my code but test cases failed!
import React, { useState } from "react";
const intialFeedback = [{ name: "Readability", upvote: 0, downvote: 0 }, { name: "Performance", upvote: 0, downvote: 0 }, { name: "Security", upvote: 0, downvote: 0 }, { name: "Documentation", upvote: 0, downvote: 0 }, { name: "Testing", upvote: 0, downvote: 0 }];
const FeedbackSystem = () => { const [feedback, setFeedback] = useState(intialFeedback)
const handleUpVote = (name) => { setFeedback(pre => { return pre.map(item => { if(item.name === name){ item.upvote+=1; }
}
const handleDownVote = (name) => { setFeedback(pre => { return pre.map(item => { if(item.name === name){ item.downvote+=1; }
}
return ( {feedback.map((item, index) => {handleDownVote(item.name)}} handleUpVote={()=>{handleUpVote(item.name)}} index={index} {...item} /> )} ); };
export default FeedbackSystem;
function FeedbackCard({ name,upvote, downvote, handleDownVote, handleUpVote, index }) { return (
{name}
upvote-btn-{index}} onClick={handleDownVote}> 👎 Downvote upvote-count-${index}}> Upvotes: {upvote} downvote-count-${index}}> Downvotes: {downvote} ) }