Skip to content

Instantly share code, notes, and snippets.

@pubudu-ranasinghe
Last active November 3, 2019 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pubudu-ranasinghe/df3f7946f93c78883e2e6376903a6596 to your computer and use it in GitHub Desktop.
Save pubudu-ranasinghe/df3f7946f93c78883e2e6376903a6596 to your computer and use it in GitHub Desktop.
react-context-example-01
import React from "react";
export function NewItem({ add }) {
return (
<div className="Item">
<input type="text" placeholder="New Task"></input>
<button onClick={() => add("New")}>Add</button>
</div>
);
}
export function ItemList({ items = [], remove }) {
return items.map((item, i) => <Item text={item} index={i} key={i} remove={remove} />);
}
export function Item({ text, index, remove }) {
return (
<div className="Item">
{index + 1} {text}
<span onClick={() => remove(index)}>Done</span>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment