import { useState, useEffect, useRef, useContext } from "react"; import classNames from "classnames"; const Answers = (props) => { const { poll, user, socket, id, pid } = props; const [winner, setWinner] = useState(0); const token = localStorage.getItem(id) const onVote = async (answer) => { const data = { user:user, answer:answer, pid:pid, token:token } socket.emit("vote", data); }; useEffect(() => { var res = poll.users.reduce(function (obj, v) { obj[v.vote] = (obj[v.vote] || 0) + 1; return obj; }, {}) const arr = Object.values(res); const max = Math.max(...arr) setWinner(max) }, [poll]) const countVotes = (index) => { let count = 0 poll.users.filter(function (item) { if (item.vote === index) { count = count + 1 } }) return (