以下是我的待办事项列表代码,我无法在删除项目功能中删除列表中的项目,请帮助我解决错误。
import React, { useState } from "react";
import "./styles.css";
export default function App() {
const [inputList, setInputList] = useState("");
const [items, setItems] = useState([]);
const change1 = (e) => {
setInputList(e.target.value);
};
const change2 = () => {
setItems((oldItems) => {
return [...oldItems, inputList];
});
setInputList("");
};
const deleteItem = (ind) => {
return setItems(items.filter((item)=>{return item.ind!==ind}))
}
return (
<div className="App">
<div className="inner_div">
<h1 style={{ borderBottom: "2px solid black" }}>ToDo List</h1>
<input type="text" onChange={change1} value={inputList} />
<button onClick={change2}>+</button>
<ol style={{ listStyle: "none" }}>
{items.map((itemval, ind) => {
return (
<div style={{ display: "flex" }}>
<button onClick={deleteItem}>-</button>
<li id={ind}>{itemval}</li>
</div>
);
})}
</ol>
</div>
</div>
);
}