Created
January 10, 2022 10:40
-
-
Save Georgegriff/59d4eb17754e9acd5050336101b3a6d4 to your computer and use it in GitHub Desktop.
hooks mutations - TodoProvider adding and removing items
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
<TodoContext.Provider | |
value={{ | |
todoItems: draftTodos ? Array.from(draftTodos.values()) : [], | |
removeTodo: (id) => { | |
if (draftTodos.delete(id)) { | |
setTodoList(new Map(draftTodos)); | |
} | |
}, | |
addTodo: (message) => { | |
if (!message) { | |
return; | |
} | |
const todo = { | |
// new web api! - Support gradually increasing | |
id: crypto.randomUUID(), | |
message, | |
done: false, | |
}; | |
if (draftTodos.has(todo.id)) return; | |
draftTodos.set(todo.id, todo); | |
setTodoList(new Map(draftTodos)); | |
}, | |
}} | |
> | |
{children} | |
</TodoContext.Provider> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment