RRadioForm.tsx 696 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
import React from "react";
import { BasicQuestionType } from "../types";

type Props = {
  question: BasicQuestionType;
};

export const RRadioForm = ({ question }: Props) => {
  const result = question.answers.reduce((acc: any, cur: any) => {
    acc[cur] = (acc[cur] || 0) + 1;
    return acc;
  }, {});
Yoon, Daeki's avatar
Yoon, Daeki committed
13
  // console.log(result);
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>
  );
};