Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created June 2, 2017 22:39
Show Gist options
  • Save togakangaroo/e7fd6bc6b81d648f14507a750049ed71 to your computer and use it in GitHub Desktop.
Save togakangaroo/e7fd6bc6b81d648f14507a750049ed71 to your computer and use it in GitHub Desktop.
const CompactOrder = (props) => (
<section class="order" onclick={() => props.select(props.item) }>
<p>{props.item.name}</p>
</section>
)
class OrderList {
_constructor () {
this.state = {
orders: [
{id: 1, name: "A pencil"},
{id: 2, name: "A pen"},
]
}
},
setCurrentItem(newItem) {
this.updateState({currentlySelectedItem: item})
},
render () {
let currentlySelectedItem = null
if (this.state.currentlySelectedItem)
currentlySelectedItem = <Order item={this.state.currentlySelectedItem} />
return (
<article>
currentlySelectedItem
<ul>
{this.state.orders.map ((item) =>
<li><CompactOrder item={item} select={this.setCurrentItem.bind(this)}/></li>
)}
</ul>
</article>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment