change QuestionList, style QuestionItem

This commit is contained in:
Tatiana Nikolaeva 2025-04-05 22:42:57 +05:00
parent b3132da636
commit 065917b4d2
4 changed files with 43 additions and 10 deletions

View file

@ -6,20 +6,28 @@ interface QuestionsListProps {}
interface Question {
id: number;
text: string
}
const QuestionsList: React.FC<QuestionsListProps> = () => {
const [questions, setQuestions] = useState<Question[]>([
{id: 1},
{id: 1, text: ''},
]);
const handleAddQuestion = () => {
// Find the highest ID in the current questions list
const maxId = questions.reduce((max, question) => Math.max(max, question.id), 0);
const newQuestion: Question = {
id: maxId + 1, // Increment the ID
id: maxId + 1,
text: ''
};
setQuestions([...questions, newQuestion]); // Add the new question to the state
setQuestions([...questions, newQuestion]);
};
const handleQuestionChange = (index: number, value: string) => {
const newQuestions = [...questions];
newQuestions[index] = {...newQuestions[index], text: value};
setQuestions(newQuestions);
};
return (
@ -28,6 +36,8 @@ const QuestionsList: React.FC<QuestionsListProps> = () => {
<QuestionItem
key={question.id}
indexQuestion={index + 1}
valueQuestion={''}
onChangeQuestion={(value) => handleQuestionChange(index, value)}
/>
))}
<AddQuestionButton onClick={handleAddQuestion} />