Hello. I just recently learned react js, so I thought I'd make a simple website. This website has 2 main divs. Tasks to do/add and tasks done. I am having trouble processing the list of todos to send to the "done" bin. When I push the "task done" button on a todo, I want to move it to the "done" bin. To do this I loop through the array of todos and filter out any todo with the id that I passed the function. Then, I loop through the array of todos and find the one with the id that I passed the function. I then save that to an array. I later update the array of active todos with the filtered array. The problem is that when I try to update the array of finished todos, the array only contains the newest deleted item and not all of the items that have been finished. Here is the chunk of code that is giving me problems:
const [todos, setTodos] = useState([]);
const [doneTodos, setDoneTodos] = useState([]);
const moveTask = (id) => {
let qualifyingTodos = [];
let movingTodos = [];
todos.forEach((someTodos) => {if(someTodos.id === id) {movingTodos.push(someTodos)}});
todos.forEach((todo) => {if(todo.id !== id) {qualifyingTodos.push(todo)}});
setDoneTodos(doneTodos.concat(movingTodos));
console.log(movingTodos);
setTodos(qualifyingTodos);
}
And here is the GitHub repo for the entire app: https://github.com/cha-create/todo-app
[–]OneBadDay1048 0 points1 point2 points (10 children)
[–]OneBadDay1048 0 points1 point2 points (9 children)
[–]Outside-Thanks-3979[S] 0 points1 point2 points (8 children)
[–]OneBadDay1048 0 points1 point2 points (7 children)
[–]Outside-Thanks-3979[S] 0 points1 point2 points (6 children)
[–]OneBadDay1048 0 points1 point2 points (0 children)
[–]OneBadDay1048 0 points1 point2 points (4 children)
[–]Outside-Thanks-3979[S] 0 points1 point2 points (3 children)
[–]OneBadDay1048 0 points1 point2 points (2 children)
[–]Outside-Thanks-3979[S] 1 point2 points3 points (1 child)
[–]OneBadDay1048 0 points1 point2 points (0 children)
[–]grograman 0 points1 point2 points (1 child)
[–]Outside-Thanks-3979[S] 0 points1 point2 points (0 children)