Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
How can I remove item from todo list

I'm coding simple todo list. Delete items doesn't work by click on it. What can be wrong? Is filtering array and setting state is right?

import React from "react";
    import { useState } from "react";

export const ToDoComponent = () => {
  const inputResult = {
    id: Date.now(),
    value: "",
  };

  const [value, setValue] = useState([]);

  const onChange = (event) => {
    inputResult.value = event.target.value;
  };



  const addTask = (event) => {
    setValue([{ inputResult }, ...value]);
  };
  
  
  const delTask = (id) => {
     const res = value.filter((delId) => id !== delId.id);   
      setValue(res);
    // console.log("test")
  }; 

  return (
    <div>
      <h1 className="Title">Todo list</h1>
      <input onChange={onChange} className="Input"></input>
      <button className="Button" onClick={addTask}>
        Add task
      </button>
      <ul>
        {value.map(({ inputResult }) => (
          <li onClick = {delTask(inputResult.id)} key={inputResult.id}>
            {inputResult.value}
          </li>
        ))}
      </ul>
    </div>
  );
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!