I have a functional component, in that i have a array state with object as items. now i wanted to remove an item at particular position.
const [tasks, setTasks] = useState([
{ project: "aaaa", task: "xxxxx", status: true },
{ project: "bbbb", task: "yyyyz", status: true },
{ project: "cccc", task: "zzzzz", status: true }
]);
function addTask(task) {
setTasks(oldArray => [...oldArray, task]);
}
function deleteTask(pos) {
let _tasks = tasks;
_tasks.splice(pos, 1);
setTasks(_tasks)
}
here the task is get deleted but UI is not updated untill i add a new item to state array.