components

This commit is contained in:
Tatiana Nikolaeva 2025-04-04 21:41:22 +05:00
commit 009a214b40
40 changed files with 966 additions and 0 deletions

View file

@ -0,0 +1,2 @@
/*QuestionsList.module.css*/

View file

@ -0,0 +1,38 @@
import React, {useState} from "react";
import QuestionItem from "../QuestionItem/QuestionItem.tsx";
import AddQuestionButton from "../AddQuestionButton/AddQuestionButton.tsx";
interface QuestionsListProps {}
interface Question {
id: number;
}
const QuestionsList: React.FC<QuestionsListProps> = () => {
const [questions, setQuestions] = useState<Question[]>([
{id: 1},
]);
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
};
setQuestions([...questions, newQuestion]); // Add the new question to the state
};
return (
<>
{questions.map((question, index) => (
<QuestionItem
key={question.id}
indexQuestion={index + 1}
/>
))}
<AddQuestionButton onClick={handleAddQuestion} />
</>
);
};
export default QuestionsList;