Last active
January 10, 2022 10:46
-
-
Save Georgegriff/313382be3f3a790c3c896c4b58bf50f9 to your computer and use it in GitHub Desktop.
hooks mutations - mutations removed
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
removeTodo: (id) => { | |
// make a copy first | |
const newTodos = new Map(draftTodos); | |
if (newTodos.delete(id)) { | |
setTodoList(newTodos); | |
} | |
}, | |
addTodo: (message) => { | |
if (!message) { | |
return; | |
} | |
const todo = { | |
id: crypto.randomUUID(), | |
message, | |
done: false, | |
}; | |
if (draftTodos.has(todo.id)) return; | |
// make a copy first | |
const newTodos = new Map(draftTodos); | |
newTodos.set(todo.id, todo); | |
setTodoList(new Map(newTodos)); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment