RCheckbox.tsx 769 Bytes
Newer Older
1
import React from "react";
Yoon, Daeki's avatar
Yoon, Daeki committed
2
import { IQuestionData } from "../types";
3
import chartImg2 from "../icons/chartImg2.png";
4
5

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

9
export const RCheckbox = ({ question }: Props) => {
10
11
12
13
14
15
16
17
  const result = question.answers.flat().reduce((acc: any, cur: any) => {
    acc[cur] = (acc[cur] || 0) + 1;
    return acc;
  }, {});
  console.log(result);

  return (
    <div className="m-5">
18
      <img src={chartImg2} />
19
20
      {question.content.choices.map((choice: any, index: number) => (
        <div key={index} className="">
21
22
23
24
25
26
27
28
29
          <span className="font-bold">{choice.text}</span>
          <span className="ml-3">
            - {result[choice.text] ? result[choice.text] : 0}
          </span>
        </div>
      ))}
    </div>
  );
};