Created
January 10, 2022 10:33
-
-
Save Georgegriff/12c1ef9a6c11d193bba0585191d536a2 to your computer and use it in GitHub Desktop.
hooks mutations article snippet - AddTodo
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
import { useTodos } from "./TodoContext"; | |
export const AddTodo = () => { | |
const { addTodo } = useTodos(); | |
return ( | |
<form | |
onSubmit={(e) => { | |
e.preventDefault(); | |
const formEntries = new FormData(e.target); | |
addTodo(formEntries.get("message")); | |
}} | |
> | |
<input | |
className="Input SearchBox" | |
name="message" | |
placeholder="New item..." | |
id="addItem" | |
type="text" | |
/> | |
<button className="Button" type="submit"> | |
<span role="img" aria-label="Add item"> | |
➕ | |
</span> | |
</button> | |
</form> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment