import React, { useState } from "react"; import { RatingType } from "../types"; type Props = { element: RatingType; handleQuestion: (id: string) => void; save: boolean; }; export const RatingForm = ({ element, handleQuestion, save }: Props) => { const [choices, setChoices] = useState([...element.content.choices]); function handleContent(event: React.ChangeEvent) { const { id, value, name } = event.target; if (name === "text") { choices[+id].text = value; element.content.choices = choices; } else if (name === "minRateDescription") { element.content = { ...element.content, minRateDescription: value }; } else if (name === "maxRateDescription") { element.content = { ...element.content, maxRateDescription: value }; } handleQuestion(element._id); console.log(choices); } function deleteValue() { //제일 마지막 index 제거 choices.splice(-1, 1); element.content.choices = choices; handleQuestion(element._id); } function addValue() { choices.push({ text: "", value: choices.length }); element.content.choices = choices; handleQuestion(element._id); } return ( <>
{choices.map((choice: any, index: number) => ( ))}
); };