From 7ca8441ecffc7ca134404a49fb9f386592b0d642 Mon Sep 17 00:00:00 2001 From: Dhairya Rathod <44311424+dhairya-rathod@users.noreply.github.com> Date: Sat, 8 Apr 2023 12:04:11 +0530 Subject: [PATCH] code optimization --- src/components/Home/Home.jsx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/Home/Home.jsx b/src/components/Home/Home.jsx index 6b1702b..acad1e2 100644 --- a/src/components/Home/Home.jsx +++ b/src/components/Home/Home.jsx @@ -30,23 +30,21 @@ const Home = () => { } function updateTitle(updatedId, updatedTitle) { - const update = tasks.map(item => { - if (item.id === updatedId) { - item.title = updatedTitle; - } - return item; - }); - updateTasks(update); + const index = tasks.findIndex(item => item.id === updatedId); + if (index !== -1) { + const update = [...tasks]; + update[index].title = updatedTitle; + updateTasks(update); + } } function updateStatus(updatedId, status) { - const update = tasks.map(item => { - if (item.id === updatedId) { - item.completed = status; - } - return item; - }); - updateTasks(update); + const index = tasks.findIndex(item => item.id === updatedId); + if (index !== -1) { + const update = [...tasks]; + update[index].completed = status; + updateTasks(update); + } } return (