Skip to content

Instantly share code, notes, and snippets.

@trillionclues
Created April 20, 2023 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trillionclues/fc1c402a5f4f067dbba6c73ff570b8a2 to your computer and use it in GitHub Desktop.
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.
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