Created
April 20, 2023 12:06
-
-
Save trillionclues/fc1c402a5f4f067dbba6c73ff570b8a2 to your computer and use it in GitHub Desktop.
Handle checkbox change to validate if a todos has been checked as completed and moved to completed tab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleCheckboxChange = (id) => { | |
const todoIndex = items.findIndex((item) => item.id === id) | |
const updatedItems = [...items] | |
updatedItems[todoIndex].completed = !updatedItems[todoIndex].completed | |
if (updatedItems[todoIndex].completed) { | |
setCompletedTodo([...completedTodo, updatedItems[todoIndex].id]) | |
} else { | |
setCompletedTodo(completedTodo.filter((item) => item.id !== id)) | |
} | |
onCheckboxChange(updatedItems) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment