xxxxxxxxxx
// Javascript React array manipulation
// adding an element to array
function handleAddTask(text) {
setTasks([tasks, {id: nextId++, text: text}]);
}
// updating an element in array
function handleChangeTask(task) {
setTasks(
tasks.map((t) => {
if (t.id === task.id) {
return task;
} else {
return t;
}
})
);
}
// deleting an element from array
function handleDeleteTask(taskId) {
setTasks(tasks.filter((t) => t.id !== taskId));
}