Skip to content

Instantly share code, notes, and snippets.

@Georgegriff
Created January 10, 2022 10:33
Show Gist options
  • Save Georgegriff/12c1ef9a6c11d193bba0585191d536a2 to your computer and use it in GitHub Desktop.
Save Georgegriff/12c1ef9a6c11d193bba0585191d536a2 to your computer and use it in GitHub Desktop.
hooks mutations article snippet - AddTodo
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