I am trying to create a simple to do page using react after adding to do list item i am attaching trash icon & when user click its required its corresponding list item is deleted , i want to know if it can be done without using id, for ex in jquery it was simple (this.remove )
const [input, setValue] = useState("");
const [todos, setTodos] = useState([]);
// passing entered
const handleInput = (event) => {
setValue(event.target.value);
};
const lp = (event) => {
// let c = [1,2,34,55]
event.preventDefault();
// if no input nothing will happen return none
if (!input) return;
// using spread operator its used whenever we need to add array data to exiting array
const newTodos = [...todos, input];
setTodos(newTodos);
// clearing input text
setValue("");
};
const handeldel=(e) => {
// how to delete
}
return (
<div>
<div class="input-group mb-3">
<input
className="form-control border-primary font-weight-bold"
style={{ height: 60 }}
placeholder="Enter Text here"
type="text"
value={input}
onChange={handleInput}
/>
<div class="input-group-append">
<button
className="input-group-append font-weight-bolder "
style={{ fontSize: 20 }}
onClick={lp}
>
{" "}
<i class="fas fa-plus-square fa-2x p-2"></i>{" "}
</button>
</div>
</div>
{todos.map((x) => (
<ol style={{ listStyle: "none" }}>
<li className="font-weight-bolder table-bordered" style={{fontSize:20}}>
{x} <i class="fas fa-trash-alt" onClick={handeldel}></i>
</li>
</ol>
))}
</div>
);
};