Skip to content

Instantly share code, notes, and snippets.

@rbiggs
Created September 6, 2017 02:54
Show Gist options
  • Save rbiggs/97cb445bcd18a7eeba6cbaf6a097e413 to your computer and use it in GitHub Desktop.
Save rbiggs/97cb445bcd18a7eeba6cbaf6a097e413 to your computer and use it in GitHub Desktop.
Component with array of objects
import {h, Component} from 'composi'
const fruits = [
{
name: 'Apples',
quanity: 6
},
{
name: 'Oranges',
quanity: 3,
},
{
name: 'Bananas',
quanity: 2
},
{
name: 'Strawberries',
quanity: 20
}
]
const list = new Component({
root: 'section',
state: fruits,
// Use map on array of fruits:
render: (fruits) => (
<ul>
{
fruits.map(fruit => (
<li>
<h2>Name: {fruit.name}</h2>
<h3>Quantity: {fruit.quanitity}</h3>
</li>
)
)
}
</ul>
)
})
list.update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment