Created
September 6, 2017 02:54
-
-
Save rbiggs/97cb445bcd18a7eeba6cbaf6a097e413 to your computer and use it in GitHub Desktop.
Component with array of objects
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 {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