RDropdown.tsx 677 Bytes
Newer Older
1
import React from "react";
Yoon, Daeki's avatar
Yoon, Daeki committed
2
import { IQuestionData } from "../types";
3
4

type Props = {
Yoon, Daeki's avatar
Yoon, Daeki committed
5
  question: IQuestionData;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  answers: any;
7
8
};

Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
export const RDropdown = ({ question, answers }: Props) => {
  const result = answers.reduce((acc: any, cur: any) => {
11
12
13
    acc[cur] = (acc[cur] || 0) + 1;
    return acc;
  }, {});
Yoon, Daeki's avatar
Yoon, Daeki committed
14

15
16
  return (
    <div className="m-5">
Yoon, Daeki's avatar
Yoon, Daeki committed
17
18
      {question.content.choices.map((choice: any, index: number) => (
        <div key={index} className="">
19
20
21
22
23
24
25
26
27
          <span className="font-bold">{choice.text}</span>
          <span className="ml-3">
            - {result[choice.text] ? result[choice.text] : 0}
          </span>
        </div>
      ))}
    </div>
  );
};