我一直在尝试添加项目,添加项目之后,我想清除状态,但它似乎对我不起作用,并且卡住了。
在此按钮
<IonButton
expand="full"
color="primary"
onClick={() => [AddNewTask(), setShowAlert1(true)]}
>
Add Task
</IonButton>
添加新任务功能
const AddNewTask = () => {
const task: todoTypes = {
id: v4(),
title: newTask.title,
content: newTask.content,
color: newTask.color,
};
setNewTask({ ...initialNewTaskState });
setTodoList([...todoList, task]);
};
国家声明
const initialNewTaskState: todoTypes = {
id: "",
title: "",
content: "",
color: "primary",
};
const [todoList, setTodoList] = useState<todoTypes[]>(todoData);
const [newTask, setNewTask] = useState<todoTypes>(initialNewTaskState);