Skip to content

Instantly share code, notes, and snippets.

@Georgegriff
Last active January 10, 2022 10:46
Show Gist options
  • Save Georgegriff/313382be3f3a790c3c896c4b58bf50f9 to your computer and use it in GitHub Desktop.
Save Georgegriff/313382be3f3a790c3c896c4b58bf50f9 to your computer and use it in GitHub Desktop.
hooks mutations - mutations removed
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