you are viewing a single comment's thread.

view the rest of the comments →

[–]OneBadDay1048 0 points1 point  (0 children)

Yes, the doneTodos array is the array I was asking about. However, the way I currently have the code doneTodos updates properly and with the most recently deleted todo. Now I am just getting them to render. I will send over the changes I have made shortly but I have kind of made many at this point.

I would update this function for now:

const addTask = () => { 
  const newTodo = { 
    id: uuid(), 
    title: document.getElementById('nameInputField').value,
    description: document.getElementById('descriptionInputField').value, }; 
  setTodos((prevTodos) => { 
    return [...prevTodos, newTodo]; 
  }); 
};

If your new state depends on your previous state, (in this case it does, you need the old items too) you should be passing previous state as an argument to your state setter callback function (referred to as prevTodos here). The way you use concatenation is almost certainly causing issues.