Skip to content

Instantly share code, notes, and snippets.

Last active November 3, 2019 10:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import React, { useState, useContext } from "react";
import TodoContext from "../contexts/TodoContext";
export function NewItem() {
const [text, setText] = useState("");
// TodoContext is made available as a hook
const todoContext = useContext(TodoContext);
return (
<div className="Item">
placeholder="New Task"
onChange={e => setText(}
<button onClick={() => todoContext.add(text)}>Add</button>
export function ItemList() {
const todoContext = useContext(TodoContext);
return, i) => (
<Item text={item} index={i} key={i} remove={todoContext.remove} />
// Rest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment