RadioForm.tsx 964 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
3
4
5
import { RadioType } from "../types";

type Props = {
  element: RadioType;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  handleQuestion: (id: string) => void;
7
8
};

Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
11
12
13
14
15
16
17
18
export const RadioForm = ({ element, handleQuestion }: Props) => {
  const [choices, setChoices] = useState([...element.content.choices]);

  function handleContent(event: React.ChangeEvent<HTMLInputElement>) {
    const { id, value } = event.target;
    choices[+id].text = value;
    element.content.choices = choices;
    handleQuestion(element._id);
    console.log(choices);
  }
19
  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
20
21
22
23
24
25
26
27
28
29
30
31
32
    <div id="content" className="flex mt-4">
      {choices.map((choice: any, index: number) => (
        <div>
          <input type="radio" disabled></input>
          <input
            id={`${index}`}
            type="text"
            className="mx-2 border-b-2"
            placeholder={choice.text}
            onChange={handleContent}
          ></input>
        </div>
      ))}
33
34
35
    </div>
  );
};