You are viewing a single comment's thread. Return to all comments →
Here is my simple solution.
`import React, { useState } from "react";
const FeedbackSystem = () => { const list = [ { label: "Readability", upVote: 0, downVote: 0 }, { label: "Performance", upVote: 0, downVote: 0 }, { label: "Security", upVote: 0, downVote: 0 }, { label: "Documentation", upVote: 0, downVote: 0 }, { label: "Testing", upVote: 0, downVote: 0 } ]; const [aspectList, setAspectList] = useState(list);
const handleDownVote = (index) => { aspectList[index].downVote += 1; setAspectList([...aspectList]) }
const handleUpVote = (index) => { aspectList[index].upVote += 1; setAspectList([...aspectList]) }
return ( {aspectList.map((aspect, index) => (
export default FeedbackSystem;
`
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 →
Here is my simple solution.
`import React, { useState } from "react";
const FeedbackSystem = () => { const list = [ { label: "Readability", upVote: 0, downVote: 0 }, { label: "Performance", upVote: 0, downVote: 0 }, { label: "Security", upVote: 0, downVote: 0 }, { label: "Documentation", upVote: 0, downVote: 0 }, { label: "Testing", upVote: 0, downVote: 0 } ]; const [aspectList, setAspectList] = useState(list);
const handleDownVote = (index) => { aspectList[index].downVote += 1; setAspectList([...aspectList]) }
const handleUpVote = (index) => { aspectList[index].upVote += 1; setAspectList([...aspectList]) }
return ( {aspectList.map((aspect, index) => (
{aspect.label}
upvote-btn-{index}} onClick={() => handleDownVote(index)}> 👎 Downvote upvote-count-${index}}> Upvotes: {aspect.upVote} downvote-count-${index}}> Downvotes: {aspect.downVote} ))} ); };export default FeedbackSystem;
`