Last active
November 3, 2019 10:07
-
-
Save pubudu-ranasinghe/df3f7946f93c78883e2e6376903a6596 to your computer and use it in GitHub Desktop.
react-context-example-01
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 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